Files
grafana/public/app/core/services/timer.ts
T

31 lines
630 B
TypeScript
Raw Normal View History

2017-12-20 12:33:33 +01:00
import _ from 'lodash';
import coreModule from 'app/core/core_module';
2017-10-25 12:32:19 +02:00
// This service really just tracks a list of $timeout promises to give us a
// method for cancelling them all when we need to
2017-10-25 12:32:19 +02:00
export class Timer {
timers = [];
/** @ngInject */
2017-12-19 16:06:54 +01:00
constructor(private $timeout) {}
2017-10-25 12:32:19 +02:00
register(promise) {
this.timers.push(promise);
return promise;
}
cancel(promise) {
this.timers = _.without(this.timers, promise);
this.$timeout.cancel(promise);
}
cancelAll() {
_.each(this.timers, t => {
2017-10-25 12:32:19 +02:00
this.$timeout.cancel(t);
});
this.timers = [];
}
}
2017-12-20 12:33:33 +01:00
coreModule.service('timer', Timer);