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

104 lines
3.5 KiB
JavaScript
Raw Normal View History

2022-06-08 10:36:39 +00:00
import { __extends } from "tslib";
2022-01-21 08:28:41 +00:00
import { AsyncAction } from './AsyncAction';
2022-06-08 10:36:39 +00:00
import { Subscription } from '../Subscription';
2022-01-21 08:28:41 +00:00
import { AsyncScheduler } from './AsyncScheduler';
2022-06-08 10:36:39 +00:00
var VirtualTimeScheduler = (function (_super) {
__extends(VirtualTimeScheduler, _super);
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));
export { VirtualTimeScheduler };
2022-06-08 10:36:39 +00:00
var VirtualAction = (function (_super) {
__extends(VirtualAction, _super);
2022-01-21 08:28:41 +00:00
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) {
2022-06-08 10:36:39 +00:00
if (delay === void 0) { delay = 0; }
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);
2022-01-21 08:28:41 +00:00
}
2022-06-08 10:36:39 +00:00
else {
return Subscription.EMPTY;
2022-01-21 08:28:41 +00:00
}
};
VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
2022-06-08 10:36:39 +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-06-08 10:36:39 +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-06-08 10:36:39 +00:00
//# sourceMappingURL=VirtualTimeScheduler.js.map