clock-tickr
v0.1.0
Published
A ticker that emits tick events at a clock-sychronised, self-adjusting interval.
Downloads
20
Readme
ClockTickr :alarm_clock:
A very simple ticker that emits tick
events at a clock-sychronised, self-adjusting interval.
Features
- It ticks at the specified interval.
- It keeps itself synchronised with the system clock.
- .. more ticks.
Installation
npm install --save clock-tickr
Usage:
Create a ClockTickr instance, with an optional tick interval in ms (default is 1000
) and start it. See below.
const ClockTickr = require('clock-tickr')
let tickr = new ClockTickr({ interval: 250 })
tickr.on('tick', (tick) => {
console.log(tick)
})
tickr.start()
results in (when you change the system time while running)
...
{ actual: 1539887917504, expected: 1539887917500, drift: 4 }
{ actual: 1539887917753, expected: 1539887917750, drift: 3 }
{ actual: 1539886920168, expected: 1539887918000, drift: -997832 }
Did you travel in time?
{ actual: 1539886920501, expected: 1539886920500, drift: 1 }
{ actual: 1539886920751, expected: 1539886920750, drift: 1 }
...
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
Credits
- Jeroen Coussement - @coussej - coussej.github.io
License
MIT