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
Required
Type: (param: any) => void;
start
timer.start(ms, param)
-> 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
param
Optional
Type: any
Desc: Parameter 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(param)
-> void
timer.trigger('Hello nodejs-timer from trigger');
param
Optional
Type: any
Desc: Parameter pass to timeoutEvent