1 import { AsyncAction } from './AsyncAction';
2 import { Subscription } from '../Subscription';
3 import { QueueScheduler } from './QueueScheduler';
4 import { SchedulerAction } from '../types';
7 * We need this JSDoc comment for affecting ESDoc.
11 export class QueueAction<T> extends AsyncAction<T> {
13 constructor(protected scheduler: QueueScheduler,
14 protected work: (this: SchedulerAction<T>, state?: T) => void) {
15 super(scheduler, work);
18 public schedule(state?: T, delay: number = 0): Subscription {
20 return super.schedule(state, delay);
24 this.scheduler.flush(this);
28 public execute(state: T, delay: number): any {
29 return (delay > 0 || this.closed) ?
30 super.execute(state, delay) :
31 this._execute(state, delay) ;
34 protected requestAsyncId(scheduler: QueueScheduler, id?: any, delay: number = 0): any {
35 // If delay exists and is greater than 0, or if the delay is null (the
36 // action wasn't rescheduled) but was originally scheduled as an async
37 // action, then recycle as an async action.
38 if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
39 return super.requestAsyncId(scheduler, id, delay);
41 // Otherwise flush the scheduler starting with this action.
42 return scheduler.flush(this);