1 import { AsyncAction } from './AsyncAction';
2 import { AsyncScheduler } from './AsyncScheduler';
3 export class VirtualTimeScheduler extends AsyncScheduler {
4 constructor(SchedulerAction = VirtualAction, maxFrames = Number.POSITIVE_INFINITY) {
5 super(SchedulerAction, () => this.frame);
6 this.maxFrames = maxFrames;
11 const { actions, maxFrames } = this;
13 while ((action = actions[0]) && action.delay <= maxFrames) {
15 this.frame = action.delay;
16 if (error = action.execute(action.state, action.delay)) {
21 while (action = actions.shift()) {
28 VirtualTimeScheduler.frameTimeFactor = 10;
29 export class VirtualAction extends AsyncAction {
30 constructor(scheduler, work, index = scheduler.index += 1) {
31 super(scheduler, work);
32 this.scheduler = scheduler;
36 this.index = scheduler.index = index;
38 schedule(state, delay = 0) {
40 return super.schedule(state, delay);
43 const action = new VirtualAction(this.scheduler, this.work);
45 return action.schedule(state, delay);
47 requestAsyncId(scheduler, id, delay = 0) {
48 this.delay = scheduler.frame + delay;
49 const { actions } = scheduler;
51 actions.sort(VirtualAction.sortActions);
54 recycleAsyncId(scheduler, id, delay = 0) {
57 _execute(state, delay) {
58 if (this.active === true) {
59 return super._execute(state, delay);
62 static sortActions(a, b) {
63 if (a.delay === b.delay) {
64 if (a.index === b.index) {
67 else if (a.index > b.index) {
74 else if (a.delay > b.delay) {
82 //# sourceMappingURL=VirtualTimeScheduler.js.map