© 2016, Onur Yıldırım (@onury). MIT License.
A timer utility for running periodic tasks on the given interval ticks. This is useful when you want to run or schedule multiple tasks (on a single timer instance).
Universal module. Works in both Node and Browser. Less than 3KB (minified, gzipped).
npm i tasktimer --save
How it works
- When you create a timer; you set a time-interval, to be used as base resolution (tick) for the tasks.
- Then add task(s) to be executed on tick-intervals and (optionally) define number of total runs.
- Event listeners can be added to be invoked on each
- Remove or reset individual tasks at anytime.
- Or start, pause, resume or stop the timer. Effects all tasks.
In Node/CommonJS environments:
var TaskTimer = ;
via script tag in the browser:
// Timer with 1000ms (1 second) base interval resolution.var timer = 1000// interval can be updated anytime by setting the `timer.interval` property.// Add task(s) based on tick intervals.timer;// Execute some code on each tick... (every 1 second)timer;// Start the timertimerstart;
See API documentation and examples here.