Suggest an editImprove this articleRefine the answer for “What does exhaustMap do?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**exhaustMap** is an RxJS operator that ignores new values until the current inner Observable completes, guarding against repeated user actions. **Key point:** unlike switchMap, exhaustMap doesn't cancel the current operation, it simply ignores new ones, making it ideal for guarding against double-clicks and duplicate submits.Shown above the full answer for quick recall.Answer (EN)ImageThe last operator from the "big four" RxJS map operators. ## In short (as in an interview) **exhaustMap** is an RxJS operator that **ignores new values until the current inner Observable completes**. It's used to guard against **repeated user actions** (for example, a double click). ## In detail `exhaustMap` works like this: 1. a value arrives from the source Observable 2. an inner Observable is created 3. while it runs, **all new values are ignored** 4. once it completes, the next value can be accepted ### Example ```ts import { fromEvent } from 'rxjs'; import { exhaustMap } from 'rxjs/operators'; fromEvent(button, 'click').pipe( exhaustMap(() => this.http.post('/save', data)) ).subscribe(); ``` If the user clicks: ``` click click click click ``` only **one HTTP request** executes, the rest are ignored. ## Visually ``` source: a----b----c exhaustMap: inner a: ---------- b ignored c ignored result: ---------- ``` ## When exhaustMap is used Very typical Angular use cases: - form submit - login - payment - preventing double-clicks - guarding against repeated HTTP requests For example: ```ts this.loginClicks$.pipe( exhaustMap(() => this.authService.login()) ) ``` ## Difference from other map operators This is an almost mandatory question at an Angular interview. | Operator | Behavior | |---|---| | switchMap | cancels the previous one | | concatMap | queue | | mergeMap | in parallel | | exhaustMap | ignores new ones | ## An important nuance `exhaustMap` **does not cancel the current operation**, it simply ignores new ones. This is the main difference from `switchMap`. ## A typical follow-up question Very often asked: **switchMap vs exhaustMap?** Short answer: - switchMap → cancels the previous one - exhaustMap → ignores new ones ## A real Angular use case ```ts fromEvent(button, 'click').pipe( exhaustMap(() => this.api.save()) ) ``` Protects against: - double submit - duplicate requests - accidental clicks ## A mini cheat sheet for map operators In an interview, you can answer like this: > switchMap - switches > concatMap - queue > mergeMap - parallel > exhaustMap - ignoresFor the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.