Timer class for Node.js

I’m not a fan of the setInterval idea in JavaScript. I’ve seen timers implemented in a much better way in a certain ECMAScript based language that shall remain nameless.

That’s why I’ve created a Timer class for Node.js that uses EventEmitter and allows you to think of timers in an Object-Oriented way.

Here’s a simple example:

//Creates a timer that runs 10 times, once every 100ms.
var timer = new Timer(100, 10);
timer.on('timer', function(ev)
{
    console.log('Timer fired ' + timer.currentCount);
}
timer.start();

You can also stop the timer using timer.stop(), stop and reset the current count using timer.reset() and change the delay with timer.delay = 1000.

 
30
Kudos
 
30
Kudos

Now read this

Let’s Encrypt on Google App Engine

Let’s Encrypt is a pretty awesome initiative to provide free SSL certificates to make creating a secure website easy. It comes with support for automatic installation on Apache and nginx, but requires some extra work for other servers.... Continue →