@ambassify/clock v1.0.0
@ambassify/clock
A timer with drift correction
Installation
npm install --save @ambassify/clockUsage
const Clock = require('@ambassify/clock');
const clock = new Clock(1000);
clock.on('tick', function() {
console.log('1000ms elapsed');
});
clock.start();API
Clock
new Clock(<interval>, [handler])
intervalis the interval at which to fire thetickevent in milliseconds.handleroptionally, a default handler for thetickevent which will be attached for you.
.start()
Starts the interval, from this point onwards the tick event will fire every interval milliseconds.
.stop()
Stops the clock from ticking, no tick events will be fired until the clock is restarted using .start().
.on('tick', <handler>)
Attaches a new tick handler to the clock, a clock can have many tick handlers at the same time.
.off(`tick`, <handler>)
Detaches the handler function from the clock such that it will no longer receive tick events.
Contributing
If you have some issue or code you would like to add, feel free to open a Pull Request or Issue and we will look into it as soon as we can.
License
We are releasing this under a MIT License.
About us
If you would like to know more about us, be sure to have a look at our website, or our Twitter accounts Ambassify, Sitebase, JorgenEvens
8 years ago