Get better accuracy on every tick compared to setInterval() method.
npm:
npm i ez-timer --save
import { Timer } from 'ez-timer';
const timer1 = new Timer(() => console.log('tick'), 1000);
const timer2 = new Timer();
timer1.start(); // start timer
timer1.stop(); // stop timer
timer2.start(10000, () => console.log('complete')); // run for 10 seconds
- Optionally set the callback function that will be trigged on every interval.
- Optionally set the refresh interval in ms.
- Optionally set the error callback function that will be trigged on error happened.
- Starts timer running for a duration specified in ms.
- Optionally set callback function that will be trigged on the timer end.
- Stops timer.