wishthis/node_modules/rxjs/dist/cjs/internal/scheduler/VirtualTimeScheduler.js

121 lines
4.5 KiB
JavaScript
Raw Normal View History

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-06-08 10:36:39 +00:00
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
2022-01-21 08:28:41 +00:00
return extendStatics(d, b);
2022-06-08 10:36:39 +00:00
};
2022-01-21 08:28:41 +00:00
return function (d, b) {
2022-06-08 10:36:39 +00:00
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
2022-01-21 08:28:41 +00:00
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
2022-06-08 10:36:39 +00:00
exports.VirtualAction = exports.VirtualTimeScheduler = void 0;
2022-01-21 08:28:41 +00:00
var AsyncAction_1 = require("./AsyncAction");
2022-06-08 10:36:39 +00:00
var Subscription_1 = require("../Subscription");
2022-01-21 08:28:41 +00:00
var AsyncScheduler_1 = require("./AsyncScheduler");
var VirtualTimeScheduler = (function (_super) {
__extends(VirtualTimeScheduler, _super);
2022-06-08 10:36:39 +00:00
function VirtualTimeScheduler(schedulerActionCtor, maxFrames) {
if (schedulerActionCtor === void 0) { schedulerActionCtor = VirtualAction; }
if (maxFrames === void 0) { maxFrames = Infinity; }
var _this = _super.call(this, schedulerActionCtor, 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-06-08 10:36:39 +00:00
var error;
var action;
2022-01-21 08:28:41 +00:00
while ((action = actions[0]) && action.delay <= maxFrames) {
actions.shift();
this.frame = action.delay;
2022-06-08 10:36:39 +00:00
if ((error = action.execute(action.state, action.delay))) {
2022-01-21 08:28:41 +00:00
break;
}
}
if (error) {
2022-06-08 10:36:39 +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-06-08 10:36:39 +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-06-08 10:36:39 +00:00
if (Number.isFinite(delay)) {
if (!this.id) {
return _super.prototype.schedule.call(this, state, delay);
}
this.active = false;
var action = new VirtualAction(this.scheduler, this.work);
this.add(action);
return action.schedule(state, delay);
}
else {
return Subscription_1.Subscription.EMPTY;
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);
2022-09-30 13:48:25 +00:00
return 1;
2022-01-21 08:28:41 +00:00
};
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