sprinkle

sprinkle.js ===========

npm install sprinkle
4 downloads in the last month

(¯'•.¸(¯º¤ø,¸¸,ø¤º Sprinkles! º¤ø,¸¸,ø¤º¯)¸.•'¯)

Periodically invoke a callback using ticks instead calling setInterval. No memory leaks!

Example

var sprinkle = require("sprinkle"),
fs = require("fs"),
collection = {};

//call this function every second or so
var persistData = sprinkle(function() {
    fs.writeFileSync(__dirname + "/collection.json", JSON.stringify(collection));
}, 1000);

var storage = {
    get: function(key) {
        return collection[key];
    },
    set: function(key, value) {
        collection[key] = value;

        //persist data, but every ~1 second, not every time. It helps
        //if the tick callback is shoved somewhere that's called often.
        persistData(); 
    }
};
npm loves you