Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | import { Scheduler } from '../Scheduler';
|
---|
2 | export class AsyncScheduler extends Scheduler {
|
---|
3 | constructor(SchedulerAction, now = Scheduler.now) {
|
---|
4 | super(SchedulerAction, () => {
|
---|
5 | if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
|
---|
6 | return AsyncScheduler.delegate.now();
|
---|
7 | }
|
---|
8 | else {
|
---|
9 | return now();
|
---|
10 | }
|
---|
11 | });
|
---|
12 | this.actions = [];
|
---|
13 | this.active = false;
|
---|
14 | this.scheduled = undefined;
|
---|
15 | }
|
---|
16 | schedule(work, delay = 0, state) {
|
---|
17 | if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
|
---|
18 | return AsyncScheduler.delegate.schedule(work, delay, state);
|
---|
19 | }
|
---|
20 | else {
|
---|
21 | return super.schedule(work, delay, state);
|
---|
22 | }
|
---|
23 | }
|
---|
24 | flush(action) {
|
---|
25 | const { actions } = this;
|
---|
26 | if (this.active) {
|
---|
27 | actions.push(action);
|
---|
28 | return;
|
---|
29 | }
|
---|
30 | let error;
|
---|
31 | this.active = true;
|
---|
32 | do {
|
---|
33 | if (error = action.execute(action.state, action.delay)) {
|
---|
34 | break;
|
---|
35 | }
|
---|
36 | } while (action = actions.shift());
|
---|
37 | this.active = false;
|
---|
38 | if (error) {
|
---|
39 | while (action = actions.shift()) {
|
---|
40 | action.unsubscribe();
|
---|
41 | }
|
---|
42 | throw error;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 | //# sourceMappingURL=AsyncScheduler.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.