| 1 |
import { Scheduler } from '../Scheduler'; |
| 2 |
export class AsyncScheduler extends Scheduler { |
| 3 |
constructor(SchedulerAction, now = Scheduler.now) { |
| 4 |
super(SchedulerAction, now); |
| 5 |
this.actions = []; |
| 6 |
this._active = false; |
| 7 |
} |
| 8 |
flush(action) { |
| 9 |
const { actions } = this; |
| 10 |
if (this._active) { |
| 11 |
actions.push(action); |
| 12 |
return; |
| 13 |
} |
| 14 |
let error; |
| 15 |
this._active = true; |
| 16 |
do { |
| 17 |
if ((error = action.execute(action.state, action.delay))) { |
| 18 |
break; |
| 19 |
} |
| 20 |
} while ((action = actions.shift())); |
| 21 |
this._active = false; |
| 22 |
if (error) { |
| 23 |
while ((action = actions.shift())) { |
| 24 |
action.unsubscribe(); |
| 25 |
} |
| 26 |
throw error; |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
//# sourceMappingURL=AsyncScheduler.js.map |