1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/public/js/utils/Timer.js
Anders Olsen Sandvik a96a9f38ce #108 Add eslint-config-spt and remove jshint (#111)
* #108 Add eslint-config-spt

* #108 Ignore bundle.js file

* #108 Change eslint ignore path to a glob file

* Remove jshint and follow more of eslint rules
2020-02-20 08:30:24 +01:00

28 lines
610 B
JavaScript

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);
this.cb();
};
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;