3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 20:22:39 +01:00
dbot/timer.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

var timers = function() {
var timers = [];
var timeouts = [];
return {
'addTimer': function(interval, callback) { // Because who puts the callback first. Really.
var timer = setInterval(callback, interval);
timers.push(timer);
return timer;
},
'addOnceTimer': function(delay, callback) { // Because who seriously puts the callback first here too?
var timeout = setTimeout(callback, delay);
timeouts.push(timeout);
return timeout;
},
'clearTimers': function() {
for(var i;i<timers.length;i++) {
clearInterval(timers[i]);
}
for(var i;i<timeouts.length;i++) {
clearTimeout(timeouts[i]);
}
},
'clearTimer': function(id) {
clearTimer(id);
},
'clearTimeout': function(id) {
clearTimeout(id);
}
};
};
exports.create = function() {
return timers();
}