Whenever a new value is emitted by this.selectedLanguage$
, I need to emit a value that is calculated asynchronously.
My current approach to this requirement involves the following code:
public readonly languageCategories$ = this.selectedLanguage$.pipe(
switchMap(x => this._matchService.getCategoriesAsync(x)),
shareReplay());
I opted for using switchMap
due to the fact that if the selectedLanguage
changes during category retrieval, any ongoing async call should be abandoned in favor of starting a fresh one.
The issue lies in the fact that everytime the asynchronous method begins execution, I would like languageCategories
to emit a value of null
(indicating that categories are being computed, as an empty array might be misleading).
Is there a way to accomplish this?
Your assistance is greatly appreciated!