1 import { Action } from './Action';
2 export class AsyncAction extends Action {
3 constructor(scheduler, work) {
4 super(scheduler, work);
5 this.scheduler = scheduler;
9 schedule(state, delay = 0) {
15 const scheduler = this.scheduler;
17 this.id = this.recycleAsyncId(scheduler, id, delay);
21 this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
24 requestAsyncId(scheduler, id, delay = 0) {
25 return setInterval(scheduler.flush.bind(scheduler, this), delay);
27 recycleAsyncId(scheduler, id, delay = 0) {
28 if (delay !== null && this.delay === delay && this.pending === false) {
34 execute(state, delay) {
36 return new Error('executing a cancelled action');
39 const error = this._execute(state, delay);
43 else if (this.pending === false && this.id != null) {
44 this.id = this.recycleAsyncId(this.scheduler, this.id, null);
47 _execute(state, delay) {
49 let errorValue = undefined;
55 errorValue = !!e && e || new Error(e);
64 const scheduler = this.scheduler;
65 const actions = scheduler.actions;
66 const index = actions.indexOf(this);
70 this.scheduler = null;
72 actions.splice(index, 1);
75 this.id = this.recycleAsyncId(scheduler, id, null);
80 //# sourceMappingURL=AsyncAction.js.map