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 = consoleplanner
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
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 = consoleplannerplanner // => true
flushAll()
Inmmediatly execs every scheduled and cleans all from the planner
planner
deleteAll()
Deletes all scheduled tasks
planner
delete(pid)
Deletes a scheduled task by PID number.
planner
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 = consoleplannerplanner
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
plannersize