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);

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.


Now read this

Load balancing WebSockets with ELB and nginx on EC2

Following this guide will allow you to create an Elastic Load Balancer for a WebSocket application with support for SSL and the ability to read client IP addresses. Setup an Elastic Load Balancer Enable TCP forwarding on port 80. If you... Continue →