1.0.2 • Published 5 years ago

timeout-planner v1.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

timeout-planner

Plans and manage yours setTimeout

timeout-planner is a library for manage yours setTimeout. It brings an easy API to schedule new jobs, delete it, flush all ...

Usage

Install it through npm:

npm install timeout-planner

schedule(Function, delayInMilliseconds)

Schedule a task in the time an add it to the planner.

const delayedFn = () => console.log('🐐')
planner.schedule(delayedFn, 1000)

Returns an object with the info related to the task to execute:

{
  pid: task pid
  fn: Function to execute,
  releaseTime: Date when the task will be executed
}

exec(pid)

Inmmediatly execs the task by Id and cleans it from the planner

planner.exec(44)

Returns a boolean with the result of the execution, if it is false means that the PID doesn't exists.

has(Function)

Returns true or false depending if the parameter's functions is planned or not.

const delayedFn = () => console.log('🐐')
planner.schedule(delayedFn, 1000)
planner.has(delayedFn) // => true

flushAll()

Inmmediatly execs every scheduled and cleans all from the planner

planner.flushAll()

deleteAll()

Deletes all scheduled tasks

planner.deleteAll()

delete(pid)

Deletes a scheduled task by PID number.

planner.delete(44)

Returns a boolean with the result of delete, if it is false means that the PID doesn't exists.

deleteByFunction(Function)

Deletes a scheduled task by function

const delayedFn = () => console.log('🐐')
planner.schedule(delayedFn, 1000)
planner.deleteByFunction(delayedFn)

Returns a boolean with the result of delete, if it is false means that the PID doesn't exists.

size()

Returns current tasks scheduled number

planner.size()