2022-05-29 09:24:36 +00:00
|
|
|
/** PURE_IMPORTS_START tslib,_AsyncAction,_AsyncScheduler PURE_IMPORTS_END */
|
|
|
|
import * as tslib_1 from "tslib";
|
2022-01-21 08:28:41 +00:00
|
|
|
import { AsyncAction } from './AsyncAction';
|
|
|
|
import { AsyncScheduler } from './AsyncScheduler';
|
2022-05-29 09:24:36 +00:00
|
|
|
var VirtualTimeScheduler = /*@__PURE__*/ (function (_super) {
|
|
|
|
tslib_1.__extends(VirtualTimeScheduler, _super);
|
|
|
|
function VirtualTimeScheduler(SchedulerAction, maxFrames) {
|
|
|
|
if (SchedulerAction === void 0) {
|
|
|
|
SchedulerAction = VirtualAction;
|
|
|
|
}
|
|
|
|
if (maxFrames === void 0) {
|
|
|
|
maxFrames = Number.POSITIVE_INFINITY;
|
|
|
|
}
|
|
|
|
var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
|
2022-01-21 08:28:41 +00:00
|
|
|
_this.maxFrames = maxFrames;
|
|
|
|
_this.frame = 0;
|
|
|
|
_this.index = -1;
|
|
|
|
return _this;
|
|
|
|
}
|
|
|
|
VirtualTimeScheduler.prototype.flush = function () {
|
|
|
|
var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
|
2022-05-29 09:24:36 +00:00
|
|
|
var error, action;
|
2022-01-21 08:28:41 +00:00
|
|
|
while ((action = actions[0]) && action.delay <= maxFrames) {
|
|
|
|
actions.shift();
|
|
|
|
this.frame = action.delay;
|
2022-05-29 09:24:36 +00:00
|
|
|
if (error = action.execute(action.state, action.delay)) {
|
2022-01-21 08:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error) {
|
2022-05-29 09:24:36 +00:00
|
|
|
while (action = actions.shift()) {
|
2022-01-21 08:28:41 +00:00
|
|
|
action.unsubscribe();
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
VirtualTimeScheduler.frameTimeFactor = 10;
|
|
|
|
return VirtualTimeScheduler;
|
|
|
|
}(AsyncScheduler));
|
|
|
|
export { VirtualTimeScheduler };
|
2022-05-29 09:24:36 +00:00
|
|
|
var VirtualAction = /*@__PURE__*/ (function (_super) {
|
|
|
|
tslib_1.__extends(VirtualAction, _super);
|
2022-01-21 08:28:41 +00:00
|
|
|
function VirtualAction(scheduler, work, index) {
|
2022-05-29 09:24:36 +00:00
|
|
|
if (index === void 0) {
|
|
|
|
index = scheduler.index += 1;
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
var _this = _super.call(this, scheduler, work) || this;
|
|
|
|
_this.scheduler = scheduler;
|
|
|
|
_this.work = work;
|
|
|
|
_this.index = index;
|
|
|
|
_this.active = true;
|
|
|
|
_this.index = scheduler.index = index;
|
|
|
|
return _this;
|
|
|
|
}
|
|
|
|
VirtualAction.prototype.schedule = function (state, delay) {
|
2022-05-29 09:24:36 +00:00
|
|
|
if (delay === void 0) {
|
|
|
|
delay = 0;
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2022-05-29 09:24:36 +00:00
|
|
|
if (!this.id) {
|
|
|
|
return _super.prototype.schedule.call(this, state, delay);
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2022-05-29 09:24:36 +00:00
|
|
|
this.active = false;
|
|
|
|
var action = new VirtualAction(this.scheduler, this.work);
|
|
|
|
this.add(action);
|
|
|
|
return action.schedule(state, delay);
|
2022-01-21 08:28:41 +00:00
|
|
|
};
|
|
|
|
VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
|
2022-05-29 09:24:36 +00:00
|
|
|
if (delay === void 0) {
|
|
|
|
delay = 0;
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
this.delay = scheduler.frame + delay;
|
|
|
|
var actions = scheduler.actions;
|
|
|
|
actions.push(this);
|
|
|
|
actions.sort(VirtualAction.sortActions);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
|
2022-05-29 09:24:36 +00:00
|
|
|
if (delay === void 0) {
|
|
|
|
delay = 0;
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
VirtualAction.prototype._execute = function (state, delay) {
|
|
|
|
if (this.active === true) {
|
|
|
|
return _super.prototype._execute.call(this, state, delay);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
VirtualAction.sortActions = function (a, b) {
|
|
|
|
if (a.delay === b.delay) {
|
|
|
|
if (a.index === b.index) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (a.index > b.index) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (a.delay > b.delay) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return VirtualAction;
|
|
|
|
}(AsyncAction));
|
|
|
|
export { VirtualAction };
|
2022-05-29 09:24:36 +00:00
|
|
|
//# sourceMappingURL=VirtualTimeScheduler.js.map
|