ez-timer
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

ez-timer

npm dependencies downloads license

Get better accuracy on every tick compared to setInterval() method.

Installation

npm:

npm i ez-timer --save

Example Usage

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

Usage

timer = new Timer(callback, interval, errorCallback)

  • 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.

timer.start(duration, callback)

  • Starts timer running for a duration specified in ms.
  • Optionally set callback function that will be trigged on the timer end.

timer.stop()

  • Stops timer.

Readme

Keywords

Package Sidebar

Install

npm i ez-timer

Weekly Downloads

0

Version

1.1.1

License

ISC

Unpacked Size

8.03 kB

Total Files

7

Last publish

Collaborators

  • krsntn