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

Setting up Auto Scaling on EC2

This post is specifically about Ubuntu, but the process is similar for other operating systems. You’ll need to have an S3 bucket, and know how to launch EC2 instances. Here’s a quick overview of the process: Create a bootstrap script... Continue →