/nodejs-timer

nodejs-timer

Primary LanguageJavaScriptMIT LicenseMIT

nodejs-timer Build Status

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

// Create a 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.

// start the timer
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.

// clear (stop) the timer
timer.clear();

isRunning

timer.isRunning() -> boolean

Returns true is the timer is running. otherwise, return false.

// Get the time isRunning
timer.isRunning();

trigger

timer.trigger(...params) -> void

// trigger the timeoutEvent
timer.trigger('Hello nodejs-timer from trigger');
...params

Optional
Type: T extends any[]
Desc: Parameters pass to timeoutEvent