1 /** PURE_IMPORTS_START tslib,_AsyncAction,_AsyncScheduler PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { AsyncAction } from './AsyncAction';
4 import { AsyncScheduler } from './AsyncScheduler';
5 var VirtualTimeScheduler = /*@__PURE__*/ (function (_super) {
6 tslib_1.__extends(VirtualTimeScheduler, _super);
7 function VirtualTimeScheduler(SchedulerAction, maxFrames) {
8 if (SchedulerAction === void 0) {
9 SchedulerAction = VirtualAction;
11 if (maxFrames === void 0) {
12 maxFrames = Number.POSITIVE_INFINITY;
14 var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
15 _this.maxFrames = maxFrames;
20 VirtualTimeScheduler.prototype.flush = function () {
21 var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
23 while ((action = actions[0]) && action.delay <= maxFrames) {
25 this.frame = action.delay;
26 if (error = action.execute(action.state, action.delay)) {
31 while (action = actions.shift()) {
37 VirtualTimeScheduler.frameTimeFactor = 10;
38 return VirtualTimeScheduler;
40 export { VirtualTimeScheduler };
41 var VirtualAction = /*@__PURE__*/ (function (_super) {
42 tslib_1.__extends(VirtualAction, _super);
43 function VirtualAction(scheduler, work, index) {
44 if (index === void 0) {
45 index = scheduler.index += 1;
47 var _this = _super.call(this, scheduler, work) || this;
48 _this.scheduler = scheduler;
52 _this.index = scheduler.index = index;
55 VirtualAction.prototype.schedule = function (state, delay) {
56 if (delay === void 0) {
60 return _super.prototype.schedule.call(this, state, delay);
63 var action = new VirtualAction(this.scheduler, this.work);
65 return action.schedule(state, delay);
67 VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
68 if (delay === void 0) {
71 this.delay = scheduler.frame + delay;
72 var actions = scheduler.actions;
74 actions.sort(VirtualAction.sortActions);
77 VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
78 if (delay === void 0) {
83 VirtualAction.prototype._execute = function (state, delay) {
84 if (this.active === true) {
85 return _super.prototype._execute.call(this, state, delay);
88 VirtualAction.sortActions = function (a, b) {
89 if (a.delay === b.delay) {
90 if (a.index === b.index) {
93 else if (a.index > b.index) {
100 else if (a.delay > b.delay) {
107 return VirtualAction;
109 export { VirtualAction };
110 //# sourceMappingURL=VirtualTimeScheduler.js.map