1 | /** PURE_IMPORTS_START tslib,_Scheduler PURE_IMPORTS_END */
|
---|
2 | import * as tslib_1 from "tslib";
|
---|
3 | import { Scheduler } from '../Scheduler';
|
---|
4 | var AsyncScheduler = /*@__PURE__*/ (function (_super) {
|
---|
5 | tslib_1.__extends(AsyncScheduler, _super);
|
---|
6 | function AsyncScheduler(SchedulerAction, now) {
|
---|
7 | if (now === void 0) {
|
---|
8 | now = Scheduler.now;
|
---|
9 | }
|
---|
10 | var _this = _super.call(this, SchedulerAction, function () {
|
---|
11 | if (AsyncScheduler.delegate && AsyncScheduler.delegate !== _this) {
|
---|
12 | return AsyncScheduler.delegate.now();
|
---|
13 | }
|
---|
14 | else {
|
---|
15 | return now();
|
---|
16 | }
|
---|
17 | }) || this;
|
---|
18 | _this.actions = [];
|
---|
19 | _this.active = false;
|
---|
20 | _this.scheduled = undefined;
|
---|
21 | return _this;
|
---|
22 | }
|
---|
23 | AsyncScheduler.prototype.schedule = function (work, delay, state) {
|
---|
24 | if (delay === void 0) {
|
---|
25 | delay = 0;
|
---|
26 | }
|
---|
27 | if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
|
---|
28 | return AsyncScheduler.delegate.schedule(work, delay, state);
|
---|
29 | }
|
---|
30 | else {
|
---|
31 | return _super.prototype.schedule.call(this, work, delay, state);
|
---|
32 | }
|
---|
33 | };
|
---|
34 | AsyncScheduler.prototype.flush = function (action) {
|
---|
35 | var actions = this.actions;
|
---|
36 | if (this.active) {
|
---|
37 | actions.push(action);
|
---|
38 | return;
|
---|
39 | }
|
---|
40 | var error;
|
---|
41 | this.active = true;
|
---|
42 | do {
|
---|
43 | if (error = action.execute(action.state, action.delay)) {
|
---|
44 | break;
|
---|
45 | }
|
---|
46 | } while (action = actions.shift());
|
---|
47 | this.active = false;
|
---|
48 | if (error) {
|
---|
49 | while (action = actions.shift()) {
|
---|
50 | action.unsubscribe();
|
---|
51 | }
|
---|
52 | throw error;
|
---|
53 | }
|
---|
54 | };
|
---|
55 | return AsyncScheduler;
|
---|
56 | }(Scheduler));
|
---|
57 | export { AsyncScheduler };
|
---|
58 | //# sourceMappingURL=AsyncScheduler.js.map
|
---|