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;
|
---|
10 | }
|
---|
11 | if (maxFrames === void 0) {
|
---|
12 | maxFrames = Number.POSITIVE_INFINITY;
|
---|
13 | }
|
---|
14 | var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
|
---|
15 | _this.maxFrames = maxFrames;
|
---|
16 | _this.frame = 0;
|
---|
17 | _this.index = -1;
|
---|
18 | return _this;
|
---|
19 | }
|
---|
20 | VirtualTimeScheduler.prototype.flush = function () {
|
---|
21 | var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
|
---|
22 | var error, action;
|
---|
23 | while ((action = actions[0]) && action.delay <= maxFrames) {
|
---|
24 | actions.shift();
|
---|
25 | this.frame = action.delay;
|
---|
26 | if (error = action.execute(action.state, action.delay)) {
|
---|
27 | break;
|
---|
28 | }
|
---|
29 | }
|
---|
30 | if (error) {
|
---|
31 | while (action = actions.shift()) {
|
---|
32 | action.unsubscribe();
|
---|
33 | }
|
---|
34 | throw error;
|
---|
35 | }
|
---|
36 | };
|
---|
37 | VirtualTimeScheduler.frameTimeFactor = 10;
|
---|
38 | return VirtualTimeScheduler;
|
---|
39 | }(AsyncScheduler));
|
---|
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;
|
---|
46 | }
|
---|
47 | var _this = _super.call(this, scheduler, work) || this;
|
---|
48 | _this.scheduler = scheduler;
|
---|
49 | _this.work = work;
|
---|
50 | _this.index = index;
|
---|
51 | _this.active = true;
|
---|
52 | _this.index = scheduler.index = index;
|
---|
53 | return _this;
|
---|
54 | }
|
---|
55 | VirtualAction.prototype.schedule = function (state, delay) {
|
---|
56 | if (delay === void 0) {
|
---|
57 | delay = 0;
|
---|
58 | }
|
---|
59 | if (!this.id) {
|
---|
60 | return _super.prototype.schedule.call(this, state, delay);
|
---|
61 | }
|
---|
62 | this.active = false;
|
---|
63 | var action = new VirtualAction(this.scheduler, this.work);
|
---|
64 | this.add(action);
|
---|
65 | return action.schedule(state, delay);
|
---|
66 | };
|
---|
67 | VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
|
---|
68 | if (delay === void 0) {
|
---|
69 | delay = 0;
|
---|
70 | }
|
---|
71 | this.delay = scheduler.frame + delay;
|
---|
72 | var actions = scheduler.actions;
|
---|
73 | actions.push(this);
|
---|
74 | actions.sort(VirtualAction.sortActions);
|
---|
75 | return true;
|
---|
76 | };
|
---|
77 | VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
|
---|
78 | if (delay === void 0) {
|
---|
79 | delay = 0;
|
---|
80 | }
|
---|
81 | return undefined;
|
---|
82 | };
|
---|
83 | VirtualAction.prototype._execute = function (state, delay) {
|
---|
84 | if (this.active === true) {
|
---|
85 | return _super.prototype._execute.call(this, state, delay);
|
---|
86 | }
|
---|
87 | };
|
---|
88 | VirtualAction.sortActions = function (a, b) {
|
---|
89 | if (a.delay === b.delay) {
|
---|
90 | if (a.index === b.index) {
|
---|
91 | return 0;
|
---|
92 | }
|
---|
93 | else if (a.index > b.index) {
|
---|
94 | return 1;
|
---|
95 | }
|
---|
96 | else {
|
---|
97 | return -1;
|
---|
98 | }
|
---|
99 | }
|
---|
100 | else if (a.delay > b.delay) {
|
---|
101 | return 1;
|
---|
102 | }
|
---|
103 | else {
|
---|
104 | return -1;
|
---|
105 | }
|
---|
106 | };
|
---|
107 | return VirtualAction;
|
---|
108 | }(AsyncAction));
|
---|
109 | export { VirtualAction };
|
---|
110 | //# sourceMappingURL=VirtualTimeScheduler.js.map
|
---|