Skip to content

Commit 5252a44

Browse files
committed
feat(command-flow): use setImmediate as default scheduler
1 parent a870e0e commit 5252a44

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

packages/command-flow/src/scheduler.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,33 @@ import { forwardRef, Injectable } from '@angular/core';
22

33
@Injectable({
44
providedIn: 'root',
5-
useExisting: forwardRef(() => AnimationFrameBasedCommandFlowScheduler),
5+
useExisting: forwardRef(() => SetImmediateCommandFlowScheduler),
66
})
77
export abstract class CommandFlowScheduler {
88
abstract next(fn: () => void): void;
99
}
1010

11-
@Injectable({
12-
providedIn: 'root',
13-
})
11+
/**
12+
* Implementation of {@link CommandFlowScheduler} that uses
13+
* `setImmediate` to schedule the next execution.
14+
*/
15+
@Injectable({ providedIn: 'root' })
16+
export class SetImmediateCommandFlowScheduler implements CommandFlowScheduler {
17+
next(fn: () => void): void {
18+
setImmediate(fn);
19+
}
20+
}
21+
22+
/**
23+
* Implementation of {@link CommandFlowScheduler} that uses
24+
* `requestAnimationFrame` to schedule the next execution.
25+
* Available only in the browser platform.
26+
*/
27+
@Injectable({ providedIn: 'root' })
1428
export class AnimationFrameBasedCommandFlowScheduler
1529
implements CommandFlowScheduler
1630
{
1731
next(fn: () => void): void {
18-
requestAnimationFrame(fn);
32+
window.requestAnimationFrame(fn);
1933
}
2034
}

0 commit comments

Comments
 (0)