the manager of setInterval and setTimeout.
Maintaining a queue, iterate over all those queue and execute it if needed when every time start.
npm install crontabjs
Crontab(interval, tolerance)
interval
the interval time of crontab run. unit is ms, default is 400ms.tolerance
the maximum error of current time and last execute time. ifcurrTime + tolerance - lastExecuteTime - intervalTime
greater than 0, then this item will be run.
Also, you can use var crontab = Crontab.getInstance();
to get the only one instance.
This is for global invoke. return the same instance of Crontab. If no instance, create a new one.
register a function. same as setInterval
.
time
means the interval of function run. the unit isms
fn
means the function which wait for run.context
means the context of fn.
like on
, register once. same as setTimeout
.
clear a item which id is id
in queue. if id
not set, clear all queue.
start run crontab. this will be auto run when use new Crontab()
.
stop run crontab.
alias on(fn, time[, context])
.
alias one(fn, time[, context])
.
alias off(id)
.
alias off(id)
.
set the interval time of the current instance of crontab.
this will run stop
and start
method in turn when it invoked.
set the tolerance time of the current instance of crontab.
# test in browser
npm run-script browser
# test in terminal
mocha
# or
npm run-script test
Apache License 2.0