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

Using the Cloud Vision API on App Engine

Here’s a quick snippet of how to use the Cloud Vision API on App Engine. It’s pretty straight forward, the only tricky thing is making sure you set the Content-Type. import json from logging import info from urllib import urlencode from... Continue →