Debian Codegraph @

node/rxjs/src/internal/scheduler/AnimationFrameScheduler.ts

raw
1 import { AsyncAction } from './AsyncAction';
2 import { AsyncScheduler } from './AsyncScheduler';
3
4 export class AnimationFrameScheduler extends AsyncScheduler {
5 public flush(action?: AsyncAction<any>): void {
6 this._active = true;
7 // The async id that effects a call to flush is stored in _scheduled.
8 // Before executing an action, it's necessary to check the action's async
9 // id to determine whether it's supposed to be executed in the current
10 // flush.
11 // Previous implementations of this method used a count to determine this,
12 // but that was unsound, as actions that are unsubscribed - i.e. cancelled -
13 // are removed from the actions array and that can shift actions that are
14 // scheduled to be executed in a subsequent flush into positions at which
15 // they are executed within the current flush.
16 let flushId;
17 if (action) {
18 flushId = action.id;
19 } else {
20 flushId = this._scheduled;
21 this._scheduled = undefined;
22 }
23
24 const { actions } = this;
25 let error: any;
26 action = action || actions.shift()!;
27
28 do {
29 if ((error = action.execute(action.state, action.delay))) {
30 break;
31 }
32 } while ((action = actions[0]) && action.id === flushId && actions.shift());
33
34 this._active = false;
35
36 if (error) {
37 while ((action = actions[0]) && action.id === flushId && actions.shift()) {
38 action.unsubscribe();
39 }
40 throw error;
41 }
42 }
43 }