timeout-planner is a library for manage yours setTimeout. It brings an easy API to schedule new jobs, delete it, flush all ...
Install it through npm:
npm install timeout-planner
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
}
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.
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
Inmmediatly execs every scheduled and cleans all from the planner
planner.flushAll()
Deletes all scheduled tasks
planner.deleteAll()
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.
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.
Returns current tasks scheduled number
planner.size()