From the course: Learning RxJS
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Preventing repeated calls using exhaustMap
From the course: Learning RxJS
Preventing repeated calls using exhaustMap
- [Presenter] When we are making our weather app we have a button to admit an event to the observable to be passed to the subscribers. It can be pretty tempting to click this button multiple times. Sometimes our coaches handles the user input. Other times it can be expensive API calls we need to be careful of clicking too often. A way to fix this is to wait until the previous in progress event has been fired before creating a new one. We do this with exhaustMap, an RxJS operator that waits for the previous event to finish before starting another one. In our marble diagram, we can see how often a user wants to query the weather. While they can click the button multiple times, only the first request will be made and completed. All the other ones will be ignored until the request finishes. This ensures we're not overloading our APIs and subscribers with too many unfinished events. Turning to the code, let's see how we can…