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