2022-01-21 08:28:41 +00:00
|
|
|
"use strict";
|
|
|
|
var __extends = (this && this.__extends) || (function () {
|
|
|
|
var extendStatics = function (d, b) {
|
|
|
|
extendStatics = Object.setPrototypeOf ||
|
|
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
2022-05-29 09:24:36 +00:00
|
|
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
2022-01-21 08:28:41 +00:00
|
|
|
return extendStatics(d, b);
|
2022-05-29 09:24:36 +00:00
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
return function (d, b) {
|
|
|
|
extendStatics(d, b);
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
var AsyncAction_1 = require("./AsyncAction");
|
|
|
|
var AsyncScheduler_1 = require("./AsyncScheduler");
|
|
|
|
var VirtualTimeScheduler = (function (_super) {
|
|
|
|
__extends(VirtualTimeScheduler, _super);
|
2022-05-29 09:24:36 +00:00
|
|
|
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_1.AsyncScheduler));
|
|
|
|
exports.VirtualTimeScheduler = VirtualTimeScheduler;
|
|
|
|
var VirtualAction = (function (_super) {
|
|
|
|
__extends(VirtualAction, _super);
|
|
|
|
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) {
|
|
|
|
if (delay === void 0) { delay = 0; }
|
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) {
|
|
|
|
if (delay === void 0) { delay = 0; }
|
|
|
|
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) {
|
|
|
|
if (delay === void 0) { delay = 0; }
|
|
|
|
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_1.AsyncAction));
|
|
|
|
exports.VirtualAction = VirtualAction;
|
|
|
|
//# sourceMappingURL=VirtualTimeScheduler.js.map
|