[6a3a178] | 1 | import { AsyncAction } from './AsyncAction';
|
---|
| 2 | import { Subscription } from '../Subscription';
|
---|
| 3 | import { QueueScheduler } from './QueueScheduler';
|
---|
| 4 | import { SchedulerAction } from '../types';
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * We need this JSDoc comment for affecting ESDoc.
|
---|
| 8 | * @ignore
|
---|
| 9 | * @extends {Ignored}
|
---|
| 10 | */
|
---|
| 11 | export class QueueAction<T> extends AsyncAction<T> {
|
---|
| 12 |
|
---|
| 13 | constructor(protected scheduler: QueueScheduler,
|
---|
| 14 | protected work: (this: SchedulerAction<T>, state?: T) => void) {
|
---|
| 15 | super(scheduler, work);
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | public schedule(state?: T, delay: number = 0): Subscription {
|
---|
| 19 | if (delay > 0) {
|
---|
| 20 | return super.schedule(state, delay);
|
---|
| 21 | }
|
---|
| 22 | this.delay = delay;
|
---|
| 23 | this.state = state;
|
---|
| 24 | this.scheduler.flush(this);
|
---|
| 25 | return this;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public execute(state: T, delay: number): any {
|
---|
| 29 | return (delay > 0 || this.closed) ?
|
---|
| 30 | super.execute(state, delay) :
|
---|
| 31 | this._execute(state, delay) ;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 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);
|
---|
| 40 | }
|
---|
| 41 | // Otherwise flush the scheduler starting with this action.
|
---|
| 42 | return scheduler.flush(this);
|
---|
| 43 | }
|
---|
| 44 | }
|
---|