Simple delta time ticker
Allows setting intervals using delta time for consistency.
Differences from setInterval
:
- Tasks can be asynchronous
- Tasks that take longer than the interval won't overlap
- The intervals are more accurate
Examples
Asynchronously count to 5 with 15 millisecond intervals:
var count = 0;start;
Endless 100 millosecond interval with a synchronous task:
start;
Stop a ticker:
var ticker = start; ;
Log the interval between tasks:
var ticker = start;
Extend the ticker's config after construction:
var ticker = ; tickerstart;
Install
npm install delta-ticker
Test
make test
TODO
- An option to use
process.hrtime()
(real time) in Node.js - More accuracy tests and comparisons to
setInterval
Notes
- Depends on
Date.new
andObject.create