mirror of
https://github.com/reality/dbot.git
synced 2024-12-25 12:12:35 +01:00
28 lines
760 B
JavaScript
28 lines
760 B
JavaScript
var timers = function() {
|
|
var timers = [];
|
|
var timeouts = [];
|
|
|
|
return {
|
|
'addTimer': function(interval, callback) { // Because who puts the callback first. Really.
|
|
timers.push(setInterval(callback, interval));
|
|
},
|
|
|
|
'addOnceTimer': function(delay, callback) { // Because who seriously puts the callback first here too?
|
|
timeouts.push(setTimeout(callback, delay));
|
|
},
|
|
|
|
'clearTimers': function() {
|
|
for(var i;i<timers.length;i++) {
|
|
clearInterval(timers[i]);
|
|
}
|
|
for(var i;i<timeouts.length;i++) {
|
|
clearTimeout(timeouts[i]);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
exports.create = function() {
|
|
return timers();
|
|
}
|