Currently, I am implementing NGRX with RXJS. Within the effects layer, I am utilizing a concatMap to organize my requests in a queue fashion. However, once the latest request is finished, I aim to execute the most recent item added to the queue instead of processing all the remaining ones simultaneously. Is this scenario achievable?
I have experimented with mergeMap, switchMap, and other methods, but my requirement is to run the requests sequentially rather than concurrently. This specific necessity led me to stick to using concatMap (or any similar alternative).
updateThing$ = createEffect(() =>
this.actions$.pipe(
ofType(updateThingRequest),
concatMap((action) => {
return this.myService
//After finishing this request, I want to execute only the last pending request from the concatMap queue,
//discarding all other pending requests.
.update(action)
.pipe(
map(() => {
return someActionComplete();
}),
catchError((err) => {
return of(
someActionError()
);
})
);
})
)
);