Code coverage report for src/scheduler/FutureAction.ts

Statements: 90.32% (28 / 31)      Branches: 62.5% (5 / 8)      Functions: 100% (5 / 5)      Lines: 88.89% (24 / 27)      Ignored: none     

All files » src/scheduler/ » FutureAction.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50      1   1         23 23 23     35 34       34 34 34   34         34   34 29 29 29     34     1 22 22 5 5   22   1  
import {Subscription} from '../Subscription';
import {QueueScheduler} from './QueueScheduler';
import {Action} from './Action';
import {QueueAction} from './QueueAction';
 
export class FutureAction<T> extends QueueAction<T> {
 
  id: any;
  delay: number;
 
  constructor(public scheduler: QueueScheduler,
              public work: (x?: any) => Subscription<T> | void) {
    super(scheduler, work);
  }
 
  schedule(state?: any, Idelay: number = 0): Action {
    Iif (this.isUnsubscribed) {
      return this;
    }
 
    this.delay = delay;
    this.state = state;
    const id = this.id;
 
    Iif (id != null) {
      this.id = undefined;
      clearTimeout(id);
    }
 
    const scheduler = this.scheduler;
 
    this.id = setTimeout(() => {
      this.id = void 0;
      scheduler.actions.push(this);
      scheduler.flush();
    }, this.delay);
 
    return this;
  }
 
  unsubscribe() {
    const id = this.id;
    if (id != null) {
      this.id = void 0;
      clearTimeout(id);
    }
    super.unsubscribe();
  }
}