1 /** PURE_IMPORTS_START tslib,_Action PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Action } from './Action';
4 var AsyncAction = /*@__PURE__*/ (function (_super) {
5 tslib_1.__extends(AsyncAction, _super);
6 function AsyncAction(scheduler, work) {
7 var _this = _super.call(this, scheduler, work) || this;
8 _this.scheduler = scheduler;
10 _this.pending = false;
13 AsyncAction.prototype.schedule = function (state, delay) {
14 if (delay === void 0) {
22 var scheduler = this.scheduler;
24 this.id = this.recycleAsyncId(scheduler, id, delay);
28 this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
31 AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
32 if (delay === void 0) {
35 return setInterval(scheduler.flush.bind(scheduler, this), delay);
37 AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
38 if (delay === void 0) {
41 if (delay !== null && this.delay === delay && this.pending === false) {
47 AsyncAction.prototype.execute = function (state, delay) {
49 return new Error('executing a cancelled action');
52 var error = this._execute(state, delay);
56 else if (this.pending === false && this.id != null) {
57 this.id = this.recycleAsyncId(this.scheduler, this.id, null);
60 AsyncAction.prototype._execute = function (state, delay) {
62 var errorValue = undefined;
68 errorValue = !!e && e || new Error(e);
75 AsyncAction.prototype._unsubscribe = function () {
77 var scheduler = this.scheduler;
78 var actions = scheduler.actions;
79 var index = actions.indexOf(this);
83 this.scheduler = null;
85 actions.splice(index, 1);
88 this.id = this.recycleAsyncId(scheduler, id, null);
94 export { AsyncAction };
95 //# sourceMappingURL=AsyncAction.js.map