2013-09-13 15:52:13 -05:00
|
|
|
define([
|
|
|
|
'angular',
|
2014-08-07 07:35:19 -05:00
|
|
|
'lodash'
|
2013-09-13 15:52:13 -05:00
|
|
|
],
|
|
|
|
function (angular, _) {
|
|
|
|
'use strict';
|
|
|
|
|
2014-07-28 11:11:52 -05:00
|
|
|
var module = angular.module('grafana.services');
|
2013-09-13 15:52:13 -05:00
|
|
|
|
|
|
|
module.service('timer', function($timeout) {
|
|
|
|
// This service really just tracks a list of $timeout promises to give us a
|
|
|
|
// method for cancelling them all when we need to
|
|
|
|
|
|
|
|
var timers = [];
|
|
|
|
|
|
|
|
this.register = function(promise) {
|
|
|
|
timers.push(promise);
|
|
|
|
return promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.cancel = function(promise) {
|
|
|
|
timers = _.without(timers,promise);
|
|
|
|
$timeout.cancel(promise);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.cancel_all = function() {
|
2014-06-06 23:38:33 -05:00
|
|
|
_.each(timers, function(t) {
|
2013-09-13 15:52:13 -05:00
|
|
|
$timeout.cancel(t);
|
|
|
|
});
|
|
|
|
timers = [];
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|