timer.ts 668 B

1234567891011121314151617181920212223242526272829303132
  1. import _ from 'lodash';
  2. import coreModule from 'app/core/core_module';
  3. export class Timer {
  4. timers = [];
  5. /** @ngInject */
  6. constructor(private $timeout) {
  7. }
  8. register(promise) {
  9. this.timers.push(promise);
  10. return promise;
  11. }
  12. cancel(promise) {
  13. console.log(promise);
  14. this.timers = _.without(this.timers, promise);
  15. this.$timeout.cancel(promise);
  16. }
  17. cancelAll() {
  18. _.each(this.timers, function (t) {
  19. this.$timeout.cancel(t);
  20. });
  21. this.timers = [];
  22. }
  23. }
  24. coreModule.service('timer', Timer);
  25. // This service really just tracks a list of $timeout promises to give us a
  26. // method for cancelling them all when we need to