This lesson preview is part of the Mastering RxJS: A Compact Journey from Beginner to Pro course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to Mastering RxJS: A Compact Journey from Beginner to Pro, plus 80+ \newline books, guides and courses with the \newline Pro subscription.

[00:00 - 00:06] Hey guys, the last higher order observable is exhaust map. What's special about it is the ignoring functionality.
[00:07 - 00:16] What it means is, let me grab the timeline. What it means is whenever we start a request and then we want to start another request, the second request is actually never triggered.
[00:17 - 00:27] Basically what exhaust map does is it starts the first one and ignores all the rest until the request is done. The way I like to think about it is, imagine you're going on the ride in an amusement park.
[00:28 - 00:32] There's only one place left. So it becomes first comes first served and all the rest are ignored.
[00:33 - 00:37] Exhaust map is handy in the following scenarios. All different kinds of single click actions.
[00:38 - 00:45] For example, logging in, saving or paying. Another use case where it's being used is during the refresh token flow.
[00:46 - 00:55] Imagine you are sending different requests and all of them hit 401 at the same time. You probably don't want to call a refresh token every time a request hits 401.
[00:56 - 01:03] So instead what you do is just call it once, and ignore all the other requests. Now let's change the code and see what happens in the networking tab.
[01:04 - 01:15] In here I will remove those two operators and change concat map to exhaust map. Now when I toggle between 36 and 48, you see that no new request is happening until the first one finishes.
[01:16 - 01:35] So if I do it again, a new request has started and it's awaiting to be finished, while it's ignoring all the other requests after the first one started. And to summarize all the higher order observables, switch map is great at handling the latest request, canceling the previous one. If you need to handle all requests in parallel, use merge map.
[01:36 - 01:46] If you need to handle all requests, consecutively you should use concat map and if you only need the first request, ignoring the other requests, you should use exhaust map. That's it for this lesson.
[01:47 - 01:52] The next lesson we will look into how to combine multiple higher order observables into one single stream.