Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

sprinkle

0.0.0 • Public • Published

(¯'•.¸(¯º¤ø,¸¸,ø¤º 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(); 
    }
};

Keywords

none

install

npm i sprinkle

Downloadsweekly downloads

1

version

0.0.0

license

BSD

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability