Bones/node_modules/rxjs/scheduler/FutureAction.js
SOUTHERNCO\x2mjbyrn 7efe7605b8 Template Upload
2017-05-17 13:45:25 -04:00

65 lines
2.2 KiB
JavaScript

"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var root_1 = require('../util/root');
var Subscription_1 = require('../Subscription');
var FutureAction = (function (_super) {
__extends(FutureAction, _super);
function FutureAction(scheduler, work) {
_super.call(this);
this.scheduler = scheduler;
this.work = work;
}
FutureAction.prototype.execute = function () {
if (this.isUnsubscribed) {
throw new Error('How did did we execute a canceled Action?');
}
this.work(this.state);
};
FutureAction.prototype.schedule = function (state, delay) {
if (delay === void 0) { delay = 0; }
if (this.isUnsubscribed) {
return this;
}
return this._schedule(state, delay);
};
FutureAction.prototype._schedule = function (state, delay) {
var _this = this;
if (delay === void 0) { delay = 0; }
this.delay = delay;
this.state = state;
var id = this.id;
if (id != null) {
this.id = undefined;
root_1.root.clearTimeout(id);
}
this.id = root_1.root.setTimeout(function () {
_this.id = null;
var scheduler = _this.scheduler;
scheduler.actions.push(_this);
scheduler.flush();
}, delay);
return this;
};
FutureAction.prototype._unsubscribe = function () {
var _a = this, id = _a.id, scheduler = _a.scheduler;
var actions = scheduler.actions;
var index = actions.indexOf(this);
if (id != null) {
this.id = null;
root_1.root.clearTimeout(id);
}
if (index !== -1) {
actions.splice(index, 1);
}
this.work = null;
this.state = null;
this.scheduler = null;
};
return FutureAction;
}(Subscription_1.Subscription));
exports.FutureAction = FutureAction;
//# sourceMappingURL=FutureAction.js.map