0.0.5 • Published 9 years ago

@codexp/timer v0.0.5

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

ES6 Timer class

OO delayable interval timer

I've made this class because the setTimeout or setInterval weren't enough, or are not comfortable to use when you just need to pause or delay your timer. This is an object oriented approach for a delayable interval timer with event manager capabilities.

Here is an example on how to use it:

var Timer = require('@codexp/timer');

var timer = new Timer(1000);
var counter = 0;

// bind event handler
timer
    .on('timer', function () {
        ++counter;
        if (0 === counter % 4) {
            console.log('delaying for 3 seconds');
            this.delay(3000);
        } else {
            console.log('timer');
        }
    }.bind(timer))
    .start();

Run test script:

$ npm install @codexp/timer
$ node test
0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago