Code coverage report for src/scheduler/AsapAction.ts

Statements: 96.43% (27 / 28)      Branches: 70% (7 / 10)      Functions: 100% (4 / 4)      Lines: 96% (24 / 25)      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  1 1   5   8 8     8 8 8 8 8 4 3 3     8     1   2 2   2   2 1 1 1 1       1  
import {Action} from './Action';
import {Immediate} from '../util/Immediate';
import {FutureAction} from './FutureAction';
 
export class AsapAction<T> extends FutureAction<T> {
 
  protected _schedule(state?: any, Idelay: number = 0): Action {
    Iif (delay > 0) {
      return super._schedule(state, delay);
    }
    this.delay = delay;
    this.state = state;
    const {scheduler} = this;
    scheduler.actions.push(this);
    if (!scheduler.scheduledId) {
      scheduler.scheduledId = Immediate.setImmediate(() => {
        scheduler.scheduledId = null;
        scheduler.flush();
      });
    }
    return this;
  }
 
  protected _unsubscribe(): void {
 
    const {scheduler} = this;
    const {scheduledId, actions} = scheduler;
 
    super._unsubscribe();
 
    if (actions.length === 0) {
      scheduler.active = false;
      Eif (scheduledId != null) {
        scheduler.scheduledId = null;
        Immediate.clearImmediate(scheduledId);
      }
    }
  }
}