You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 lines
2.4 KiB

{"ast":null,"code":"import { AsyncAction } from './AsyncAction';\nimport { AsyncScheduler } from './AsyncScheduler';\nexport let VirtualTimeScheduler = /*#__PURE__*/(() => {\n class VirtualTimeScheduler extends AsyncScheduler {\n constructor(SchedulerAction = VirtualAction, maxFrames = Number.POSITIVE_INFINITY) {\n super(SchedulerAction, () => this.frame);\n this.maxFrames = maxFrames;\n this.frame = 0;\n this.index = -1;\n }\n\n flush() {\n const {\n actions,\n maxFrames\n } = this;\n let error, action;\n\n while ((action = actions[0]) && action.delay <= maxFrames) {\n actions.shift();\n this.frame = action.delay;\n\n if (error = action.execute(action.state, action.delay)) {\n break;\n }\n }\n\n if (error) {\n while (action = actions.shift()) {\n action.unsubscribe();\n }\n\n throw error;\n }\n }\n\n }\n\n VirtualTimeScheduler.frameTimeFactor = 10;\n return VirtualTimeScheduler;\n})();\nexport class VirtualAction extends AsyncAction {\n constructor(scheduler, work, index = scheduler.index += 1) {\n super(scheduler, work);\n this.scheduler = scheduler;\n this.work = work;\n this.index = index;\n this.active = true;\n this.index = scheduler.index = index;\n }\n\n schedule(state, delay = 0) {\n if (!this.id) {\n return super.schedule(state, delay);\n }\n\n this.active = false;\n const action = new VirtualAction(this.scheduler, this.work);\n this.add(action);\n return action.schedule(state, delay);\n }\n\n requestAsyncId(scheduler, id, delay = 0) {\n this.delay = scheduler.frame + delay;\n const {\n actions\n } = scheduler;\n actions.push(this);\n actions.sort(VirtualAction.sortActions);\n return true;\n }\n\n recycleAsyncId(scheduler, id, delay = 0) {\n return undefined;\n }\n\n _execute(state, delay) {\n if (this.active === true) {\n return super._execute(state, delay);\n }\n }\n\n static sortActions(a, b) {\n if (a.delay === b.delay) {\n if (a.index === b.index) {\n return 0;\n } else if (a.index > b.index) {\n return 1;\n } else {\n return -1;\n }\n } else if (a.delay > b.delay) {\n return 1;\n } else {\n return -1;\n }\n }\n\n} //# sourceMappingURL=VirtualTimeScheduler.js.map","map":null,"metadata":{},"sourceType":"module"}