File tree Expand file tree Collapse file tree
packages/command-flow/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { forwardRef , inject , Injectable , PendingTasks } from '@angular/core' ;
22
3+ /**
4+ * Service that schedules a function to be executed after the current
5+ * execution context is completed.
6+ *
7+ * Uses `MicrotaskCommandFlowScheduler` by default.
8+ *
9+ * This is usually used to schedule the dispatch of command events.
10+ */
311@Injectable ( {
412 providedIn : 'root' ,
5- useExisting : forwardRef ( ( ) => SetTimeoutCommandFlowScheduler ) ,
13+ useExisting : forwardRef ( ( ) => MicrotaskCommandFlowScheduler ) ,
614} )
715export abstract class CommandFlowScheduler {
816 abstract next ( fn : ( ) => void ) : void ;
@@ -26,6 +34,22 @@ export class SetTimeoutCommandFlowScheduler implements CommandFlowScheduler {
2634 }
2735}
2836
37+ /**
38+ * Implementation of {@link CommandFlowScheduler} that uses
39+ * `queueMicrotask` to schedule the next execution.
40+ * The scheduled function is added to {@link PendingTask} for SSR support.
41+ */
42+ export class MicrotaskCommandFlowScheduler implements CommandFlowScheduler {
43+ #tasks = inject ( PendingTasks ) ;
44+ next ( fn : ( ) => void ) : void {
45+ const done = this . #tasks. add ( ) ;
46+ queueMicrotask ( ( ) => {
47+ fn ( ) ;
48+ done ( ) ;
49+ } ) ;
50+ }
51+ }
52+
2953/**
3054 * Implementation of {@link CommandFlowScheduler} that uses
3155 * `requestAnimationFrame` to schedule the next execution.
You can’t perform that action at this time.
0 commit comments