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 Action_1 = require("./Action");
17 var AsyncAction = (function (_super) {
18 __extends(AsyncAction, _super);
19 function AsyncAction(scheduler, work) {
20 var _this = _super.call(this, scheduler, work) || this;
21 _this.scheduler = scheduler;
23 _this.pending = false;
26 AsyncAction.prototype.schedule = function (state, delay) {
27 if (delay === void 0) { delay = 0; }
33 var scheduler = this.scheduler;
35 this.id = this.recycleAsyncId(scheduler, id, delay);
39 this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
42 AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
43 if (delay === void 0) { delay = 0; }
44 return setInterval(scheduler.flush.bind(scheduler, this), delay);
46 AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
47 if (delay === void 0) { delay = 0; }
48 if (delay !== null && this.delay === delay && this.pending === false) {
54 AsyncAction.prototype.execute = function (state, delay) {
56 return new Error('executing a cancelled action');
59 var error = this._execute(state, delay);
63 else if (this.pending === false && this.id != null) {
64 this.id = this.recycleAsyncId(this.scheduler, this.id, null);
67 AsyncAction.prototype._execute = function (state, delay) {
69 var errorValue = undefined;
75 errorValue = !!e && e || new Error(e);
82 AsyncAction.prototype._unsubscribe = function () {
84 var scheduler = this.scheduler;
85 var actions = scheduler.actions;
86 var index = actions.indexOf(this);
90 this.scheduler = null;
92 actions.splice(index, 1);
95 this.id = this.recycleAsyncId(scheduler, id, null);
101 exports.AsyncAction = AsyncAction;
102 //# sourceMappingURL=AsyncAction.js.map