I am trying to wait for a function to run in async context in rxjs, but I cannot get the function to run:
export async function scan(options: TaskOptions) {
console.log("running scan");
await setTimeout(5000);
return true;
}
export const queue$ = new Subject<TaskOptions>();
const scanTasks$ = new Subject<TaskOptions>();
export const scanResult$ = scanTasks$.pipe(
switchMap((options) =>
// Doesn't run
from(scan(options)).pipe(
map(() => ({ error: undefined, success: true })),
catchError((error: Error) => of({ error, success: false }))
)
)
);
queue$.subscribe((options) => {
console.log("queue subscribe"); // runs
scanTasks$.next(options);
});
// async context
queue$.next(options)
await firstValueFrom(scanResult$)
I also tried to add .subscribe to the end of the pipe at scanResult$. What would be the proper way to get the function to run