Fixes for [#232]

This commit is contained in:
reality 2013-01-27 15:19:56 +00:00
parent bd75519047
commit 27e24a8173

View File

@ -18,23 +18,31 @@ var timers = function(dbot) {
setTimeout(function() { 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 {
callback(); callback();
} catch(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());
try {
callback(); callback();
} catch(err) {
console.log('Callback failed: ' + err);
}
}.bind(this), timeout)); }.bind(this), timeout));
} }
} }
}; };
this.onDestroy = function() { this.onDestroy = function() {
for(var i=0;i<this.runningTimeouts;i++) { for(var i=0;i<this.runningTimeouts.length;i++) {
clearTimeout(this.runningTimeouts[i]); clearTimeout(this.runningTimeouts[i]);
} }
for(i=0;i<this.runningIntervals;i++) { for(i=0;i<this.runningIntervals.length;i++) {
clearTimer(this.runningIntervals[i]); clearInterval(this.runningIntervals[i]);
} }
}.bind(this); }.bind(this);
}; };