timer.js 695 B

12345678910111213141516171819202122232425262728293031323334
  1. define([
  2. 'angular',
  3. 'lodash'
  4. ],
  5. function (angular, _) {
  6. 'use strict';
  7. var module = angular.module('grafana.services');
  8. module.service('timer', function($timeout) {
  9. // This service really just tracks a list of $timeout promises to give us a
  10. // method for cancelling them all when we need to
  11. var timers = [];
  12. this.register = function(promise) {
  13. timers.push(promise);
  14. return promise;
  15. };
  16. this.cancel = function(promise) {
  17. timers = _.without(timers,promise);
  18. $timeout.cancel(promise);
  19. };
  20. this.cancel_all = function() {
  21. _.each(timers, function(t) {
  22. $timeout.cancel(t);
  23. });
  24. timers = [];
  25. };
  26. });
  27. });