3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 04:02:39 +01:00
This commit is contained in:
reality 2013-01-29 00:53:37 +00:00
parent 53ef0288f5
commit c4a98c0df7

View File

@ -15,7 +15,7 @@ var timers = function(dbot) {
if(firstDate) { if(firstDate) {
console.log('Setting first timer to run at ' + firstDate); console.log('Setting first timer to run at ' + firstDate);
firstTimeout = firstDate.getTime() - now; firstTimeout = firstDate.getTime() - now;
setTimeout(function() { this.runningTimeouts.push(setTimeout(function() {
console.log('Running first timer at ' + new Date().toUTCString()); console.log('Running first timer at ' + new Date().toUTCString());
this.runningIntervals.push(this.api.addTimer(timeout, callback)); this.runningIntervals.push(this.api.addTimer(timeout, callback));
try { try {
@ -23,7 +23,7 @@ var timers = function(dbot) {
} catch(err) { } catch(err) {
console.log('Callback failed: ' + err); console.log('Callback failed: ' + err);
} }
}.bind(this), firstTimeout); }.bind(this), firstTimeout));
} else { } else {
this.runningIntervals.push(setInterval(function() { this.runningIntervals.push(setInterval(function() {
console.log('Running subsequent timer at ' + new Date().toUTCString()); console.log('Running subsequent timer at ' + new Date().toUTCString());
@ -39,9 +39,11 @@ var timers = function(dbot) {
this.onDestroy = function() { this.onDestroy = function() {
for(var i=0;i<this.runningTimeouts.length;i++) { for(var i=0;i<this.runningTimeouts.length;i++) {
console.log('destroying ' +this.runningTimeouts[i]);
clearTimeout(this.runningTimeouts[i]); clearTimeout(this.runningTimeouts[i]);
} }
for(i=0;i<this.runningIntervals.length;i++) { for(i=0;i<this.runningIntervals.length;i++) {
console.log('destroying ' +this.runningIntervals[i]);
clearInterval(this.runningIntervals[i]); clearInterval(this.runningIntervals[i]);
} }
}.bind(this); }.bind(this);