2 var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var AsyncAction_1 = require("./AsyncAction");
17 var AsyncScheduler_1 = require("./AsyncScheduler");
18 var VirtualTimeScheduler = (function (_super) {
19 __extends(VirtualTimeScheduler, _super);
20 function VirtualTimeScheduler(SchedulerAction, maxFrames) {
21 if (SchedulerAction === void 0) { SchedulerAction = VirtualAction; }
22 if (maxFrames === void 0) { maxFrames = Number.POSITIVE_INFINITY; }
23 var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
24 _this.maxFrames = maxFrames;
29 VirtualTimeScheduler.prototype.flush = function () {
30 var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
32 while ((action = actions[0]) && action.delay <= maxFrames) {
34 this.frame = action.delay;
35 if (error = action.execute(action.state, action.delay)) {
40 while (action = actions.shift()) {
46 VirtualTimeScheduler.frameTimeFactor = 10;
47 return VirtualTimeScheduler;
48 }(AsyncScheduler_1.AsyncScheduler));
49 exports.VirtualTimeScheduler = VirtualTimeScheduler;
50 var VirtualAction = (function (_super) {
51 __extends(VirtualAction, _super);
52 function VirtualAction(scheduler, work, index) {
53 if (index === void 0) { index = scheduler.index += 1; }
54 var _this = _super.call(this, scheduler, work) || this;
55 _this.scheduler = scheduler;
59 _this.index = scheduler.index = index;
62 VirtualAction.prototype.schedule = function (state, delay) {
63 if (delay === void 0) { delay = 0; }
65 return _super.prototype.schedule.call(this, state, delay);
68 var action = new VirtualAction(this.scheduler, this.work);
70 return action.schedule(state, delay);
72 VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
73 if (delay === void 0) { delay = 0; }
74 this.delay = scheduler.frame + delay;
75 var actions = scheduler.actions;
77 actions.sort(VirtualAction.sortActions);
80 VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
81 if (delay === void 0) { delay = 0; }
84 VirtualAction.prototype._execute = function (state, delay) {
85 if (this.active === true) {
86 return _super.prototype._execute.call(this, state, delay);
89 VirtualAction.sortActions = function (a, b) {
90 if (a.delay === b.delay) {
91 if (a.index === b.index) {
94 else if (a.index > b.index) {
101 else if (a.delay > b.delay) {
108 return VirtualAction;
109 }(AsyncAction_1.AsyncAction));
110 exports.VirtualAction = VirtualAction;
111 //# sourceMappingURL=VirtualTimeScheduler.js.map