2011-09-04 16:39:03 +02:00
|
|
|
var timers = function() {
|
|
|
|
var timers = [];
|
2012-03-12 14:45:52 +01:00
|
|
|
var timeouts = [];
|
2011-09-04 16:39:03 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
'addTimer': function(interval, callback) { // Because who puts the callback first. Really.
|
|
|
|
timers.push(setInterval(callback, interval));
|
|
|
|
},
|
2012-03-12 14:45:52 +01:00
|
|
|
|
|
|
|
'addOnceTimer': function(delay, callback) { // Because who seriously puts the callback first here too?
|
|
|
|
timeouts.push(setTimeout(callback, delay));
|
|
|
|
},
|
2011-09-04 16:39:03 +02:00
|
|
|
|
|
|
|
'clearTimers': function() {
|
|
|
|
for(var i;i<timers.length;i++) {
|
|
|
|
clearInterval(timers[i]);
|
|
|
|
}
|
2012-03-12 14:45:52 +01:00
|
|
|
for(var i;i<timeouts.length;i++) {
|
|
|
|
clearTimeout(timeouts[i]);
|
|
|
|
}
|
2011-09-04 16:39:03 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.create = function() {
|
|
|
|
return timers();
|
|
|
|
}
|