Timer for Node.js
npm i nodejs-timer
const { Timer } = require('nodejs-timer');
// Create a timer
const timer = new Timer((param) => {
console.log(param);
});
Required
Type: (...params: T) => void;
Returns false if the timer is already running. otherwise, return true.
// start the timer
timer.start(1000, 'Hello nodejs-timer');
Required
Type: number
Desc: milliseconds to trigger timeoutEvent
Optional
Type: T extends any[]
Desc: Parameters pass to timeoutEvent
Stop the timer. Returns true if the timer is running. otherwise, return false.
// clear (stop) the timer
timer.clear();
Returns true is the timer is running. otherwise, return false.
// Get the time isRunning
timer.isRunning();
// trigger the timeoutEvent
timer.trigger('Hello nodejs-timer from trigger');
Optional
Type: T extends any[]
Desc: Parameters pass to timeoutEvent