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.
|
2012-12-19 22:03:03 +01:00
|
|
|
var timer = setInterval(callback, interval);
|
|
|
|
timers.push(timer);
|
|
|
|
return timer;
|
2011-09-04 16:39:03 +02:00
|
|
|
},
|
2012-03-12 14:45:52 +01:00
|
|
|
|
|
|
|
'addOnceTimer': function(delay, callback) { // Because who seriously puts the callback first here too?
|
2012-12-19 22:03:03 +01:00
|
|
|
var timeout = setTimeout(callback, delay);
|
|
|
|
timeouts.push(timeout);
|
|
|
|
return timeout;
|
2012-03-12 14:45:52 +01:00
|
|
|
},
|
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]);
|
|
|
|
}
|
2012-12-19 22:03:03 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'clearTimer': function(id) {
|
|
|
|
clearTimer(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
'clearTimeout': function(id) {
|
|
|
|
clearTimeout(id);
|
2011-09-04 16:39:03 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.create = function() {
|
|
|
|
return timers();
|
|
|
|
}
|