Code coverage report for src/scheduler/AsapAction.ts

Statements: 96.55% (28 / 29)      Branches: 75% (6 / 8)      Functions: 100% (4 / 4)      Lines: 96.3% (26 / 27)      Ignored: none     

All files » src/scheduler/ » AsapAction.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 471 1     3     7 6       6   6   6   6 3 3 2 2 2       6     1 2 2   2   2 2 2     2 1 1     1
import {Immediate} from '../util/Immediate';
import {QueueAction} from './QueueAction';
import {Action} from './Action';
 
export class AsapAction<T> extends QueueAction<T> {
  private id: any;
 
  schedule(state?: any): Action {
    Iif (this.isUnsubscribed) {
      return this;
    }
 
    this.state = state;
 
    const scheduler = this.scheduler;
 
    scheduler.actions.push(this);
 
    if (!scheduler.scheduled) {
      scheduler.scheduled = true;
      this.id = Immediate.setImmediate(() => {
        this.id = null;
        this.scheduler.scheduled = false;
        this.scheduler.flush();
      });
    }
 
    return this;
  }
 
  unsubscribe(): void {
    const id = this.id;
    const scheduler = this.scheduler;
 
    super.unsubscribe();
 
    Eif (scheduler.actions.length === 0) {
      scheduler.active = false;
      scheduler.scheduled = false;
    }
 
    if (id) {
      this.id = null;
      Immediate.clearImmediate(id);
    }
  }
}