jstimer

1.0.14 • Public • Published

An optimized JavaScript timer

NPM version Downloads Build Status

JavaScript timer that in the background have just one native timer (setInterval)

Install

npm i jstimer -S

or

yarn add jstimer -S

Test

npm test

Use

Start one time timer (equal to setTimeout)

 
import {Timer} from 'jstimer';
 
/* Will tick each 2 seconds, 4 times. */
 
let timer = new Timer(2000, 4);
 
timer.on('tick', () => {
    console.log('timer tick');
});
 
timer.on('done', () => {
     console.log('timer done');
});
 
timer.start();
 

Start infinite timer (equal to setInterval)

 
import {Timer} from 'jstimer';
 
/* TImer will tick each 1 second, forever. */
 
let timer = new Timer(1000);
 
timer.on('tick', () => {
    console.log('timer tick');
});
 
timer.start();
 

Stop a timer

 
import {Timer} from 'jstimer';
 
let timer = new Timer(1000);
 
timer.on('tick', () => {
    console.log('timer has ticked');
});
 
timer.on('stopped', () => {
    console.log(`timer has stopped`);
});
 
timer.start();
 
setImmediate(() => {
    timer.stop();  
});
 

Package Sidebar

Install

npm i jstimer

Weekly Downloads

4

Version

1.0.14

License

MIT

Last publish

Collaborators

  • shlomi