When would I use exhaustMap over switchMap?

Discussão em 'Angular' iniciado por Heribert Greinix, Março 23, 2025.

  1. I've been digging in RxJS operators recently and have finally seem to come to an understanding between the difference between exhaustMap and switchMap (of which I only ever use the latter one). What's not clear to me is that I don't really understand why I would ever want the previous emission to complete instead of the newest one.

    Say with an API call, if I fetch some data based on a user request, I would only ever want to call the API with the latest values, right? Is exhaustMap better when the response of the API call isn't expected to change based on user action (like for example with multiple repeated clicks of the same button).

    TL;DR - What are the use-cases for exhaustMap over switchMap?

    Continue reading...

Compartilhe esta Página