rxjs-zone-less
Version:
A set of wrappers for RxJS to avoid unnecessary change detection and zone interference in Angular.
50 lines (49 loc) • 1.6 kB
JavaScript
import { __extends } from "tslib";
import { Scheduler } from '../scheduler';
var AsyncScheduler = /** @class */ (function (_super) {
__extends(AsyncScheduler, _super);
function AsyncScheduler(SchedulerAction, now) {
if (now === void 0) { now = Scheduler.now; }
var _this = _super.call(this, SchedulerAction, now) || this;
_this.actions = [];
/**
* A flag to indicate whether the Scheduler is currently executing a batch of
* queued actions.
* @type {boolean}
* @internal
*/
_this._active = false;
/**
* An internal ID used to track the latest asynchronous task such as those
* coming from `setTimeout`, `setInterval`, `requestAnimationFrame`, and
* others.
* @type {any}
* @internal
*/
_this._scheduled = undefined;
return _this;
}
AsyncScheduler.prototype.flush = function (action) {
var actions = this.actions;
if (this._active) {
actions.push(action);
return;
}
var error;
this._active = true;
do {
if ((error = action.execute(action.state, action.delay))) {
break;
}
} while ((action = actions.shift())); // exhaust the scheduler queue
this._active = false;
if (error) {
while ((action = actions.shift())) {
action.unsubscribe();
}
throw error;
}
};
return AsyncScheduler;
}(Scheduler));
export { AsyncScheduler };