@@ -7,10 +7,12 @@ import {
77 from ,
88 mergeMap ,
99 Observable ,
10+ ObservableInput ,
11+ ObservedValueOf ,
12+ OperatorFunction ,
1013 pipe ,
1114 switchMap ,
1215} from 'rxjs' ;
13- import { match } from 'ts-pattern' ;
1416
1517import { Process } from './core' ;
1618import {
@@ -69,6 +71,18 @@ export enum ProcessSchedulingStrategy {
6971 Blocking ,
7072}
7173
74+ const SCHEDULERS : Record <
75+ ProcessSchedulingStrategy ,
76+ < T , O extends ObservableInput < any > > (
77+ project : ( value : T ) => O ,
78+ ) => OperatorFunction < T , ObservedValueOf < O > >
79+ > = {
80+ [ ProcessSchedulingStrategy . Sequential ] : concatMap ,
81+ [ ProcessSchedulingStrategy . Concurrent ] : mergeMap ,
82+ [ ProcessSchedulingStrategy . Preemptive ] : switchMap ,
83+ [ ProcessSchedulingStrategy . Blocking ] : exhaustMap ,
84+ } ;
85+
7286/**
7387 * Register a `ProcessHandler` for some types of processes
7488 * within the current injection context.
@@ -120,12 +134,8 @@ export function onProcess<Types extends Type<Process<any>>[]>(
120134) : void {
121135 const injector = inject ( Injector ) ;
122136
123- const scheduler = match ( scheduling )
124- . with ( ProcessSchedulingStrategy . Sequential , ( ) => concatMap )
125- . with ( ProcessSchedulingStrategy . Concurrent , ( ) => mergeMap )
126- . with ( ProcessSchedulingStrategy . Preemptive , ( ) => switchMap )
127- . with ( ProcessSchedulingStrategy . Blocking , ( ) => exhaustMap )
128- . run ( ) ;
137+ const scheduler = SCHEDULERS [ scheduling ] ;
138+ if ( ! scheduler ) throw new Error ( `Invalid scheduling strategy: ${ scheduling } ` ) ;
129139
130140 onCommand (
131141 types ,
0 commit comments