2014-10-30 18:25:38 +01:00
|
|
|
var Timer = function(cb, interval) {
|
|
|
|
this.cb = cb;
|
|
|
|
this.interval = interval;
|
|
|
|
this.timerId = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
Timer.prototype.start = function() {
|
|
|
|
if (this.timerId != null) {
|
|
|
|
console.warn("timer already started");
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('starting timer');
|
|
|
|
this.timerId = setInterval(this.cb, this.interval);
|
2014-11-14 12:20:11 +01:00
|
|
|
this.cb();
|
2014-10-30 18:25:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Timer.prototype.stop = function() {
|
|
|
|
if (this.timerId == null) {
|
|
|
|
console.warn('no timer running');
|
|
|
|
} else {
|
|
|
|
console.log('stopping timer');
|
|
|
|
clearInterval(this.timerId);
|
|
|
|
this.timerId = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Timer;
|