-
-
Save onewland/238286 to your computer and use it in GitHub Desktop.
corrected cron.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample for http://oliveriskindoffunny.tumblr.com/post/247975858/implementing-a-user-friendly-cron-module-with-node-js | |
var cron = require('./cron'), sys = require('sys'); | |
cron.Every((2).seconds(), function() { sys.puts('Working!'); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample for http://oliveriskindoffunny.tumblr.com/post/247975858/implementing-a-user-friendly-cron-module-with-node-js | |
function TimeInterval() { | |
this.seconds = 0; | |
this.addTo = function(ti) { | |
this.seconds += ti.seconds; | |
return this; | |
}; | |
} | |
function generate_multiplier(multiplier) | |
{ | |
return function() { | |
var interval = new TimeInterval(); // use var keyword! | |
interval.seconds = this * multiplier; | |
return interval; | |
}; | |
} | |
Number.prototype.seconds = generate_multiplier(1); | |
Number.prototype.minutes = generate_multiplier(60); | |
Number.prototype.hours = generate_multiplier(3600); | |
exports.Every = function(timeInterval, callback) { | |
setInterval(callback, timeInterval.seconds * 1000); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment