1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/packages/unleash-frontend/public/js/utils/Timer.js

29 lines
762 B
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const Timer = function(cb, interval) {
2014-10-30 18:25:38 +01:00
this.cb = cb;
this.interval = interval;
this.timerId = null;
};
Timer.prototype.start = function() {
if (this.timerId != null) {
2016-06-18 22:23:19 +02:00
console.warn('timer already started'); // eslint-disable-line no-console
2014-10-30 18:25:38 +01:00
}
2016-06-18 22:23:19 +02:00
console.log('starting timer'); // eslint-disable-line no-console
2014-10-30 18:25:38 +01:00
this.timerId = setInterval(this.cb, this.interval);
this.cb();
2014-10-30 18:25:38 +01:00
};
Timer.prototype.stop = function() {
if (this.timerId == null) {
2016-06-18 22:23:19 +02:00
console.warn('no timer running'); // eslint-disable-line no-console
2014-10-30 18:25:38 +01:00
} else {
2016-06-18 22:23:19 +02:00
console.log('stopping timer'); // eslint-disable-line no-console
2014-10-30 18:25:38 +01:00
clearInterval(this.timerId);
this.timerId = null;
}
};
module.exports = Timer;