0
0
Angularframework~10 mins

mergeMap vs concatMap vs exhaustMap in Angular - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - mergeMap vs concatMap vs exhaustMap
Source Observable emits value
Operator handles inner Observable
Emit values from inner Observables
Output Observable emits merged results
When the source emits, each operator decides how to handle inner Observables: mergeMap runs all concurrently, concatMap queues them, exhaustMap ignores new while busy.
Execution Sample
Angular
source$.pipe(
  mergeMap(val => innerObservable(val))
).subscribe(console.log);
This code runs all inner Observables at once, emitting their results as they come.
Execution Table
StepSource EmitOperatorInner Observable ActionOutput Emitted
1AmergeMapStart innerObservable(A)Value A1
2BmergeMapStart innerObservable(B) concurrentlyValue B1
3A inner emits againmergeMapEmit innerObservable(A) valueValue A2
4B inner emits againmergeMapEmit innerObservable(B) valueValue B2
5CconcatMapQueue innerObservable(C)No output yet
6A inner completesconcatMapStart innerObservable(C)Value C1
7DconcatMapQueue innerObservable(D)Value C2
8C inner completesconcatMapStart innerObservable(D)Value D1
9EexhaustMapIgnore new since inner activeNo output
10D inner completesexhaustMapNo action: ignored emissions (like E) are droppedNo output
11FexhaustMapStart innerObservable(F)Value F1
12F inner emits againexhaustMapEmit innerObservable(F) valueValue F2
13No more source emits--Complete output
14End--All inner Observables completed
💡 Execution stops when source completes and all inner Observables finish emitting.
Variable Tracker
VariableStartAfter Step 2After Step 6After Step 10Final
Active inner Observables (mergeMap)02 (A,B)1 (B,C)00
Queued inner Observables (concatMap)001 (D)00
Active inner Observable (exhaustMap)00000
Key Moments - 3 Insights
Why does concatMap wait before starting the next inner Observable?
concatMap queues new inner Observables until the current one completes, as shown in execution_table rows 5-8 where C waits until A completes.
Why does exhaustMap ignore new source emissions while an inner Observable is active?
exhaustMap ignores (drops) new source values if an inner Observable is running, shown in row 9 where E is ignored while D active. Ignored emissions are not processed later.
How does mergeMap handle multiple inner Observables?
mergeMap runs all inner Observables concurrently, emitting their values as they arrive, as seen in rows 1-4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5, what does concatMap do when source emits 'C'?
AStarts innerObservable(C) immediately
BQueues innerObservable(C) to start later
CIgnores the emission 'C'
DCancels previous innerObservable
💡 Hint
Check execution_table row 5 where concatMap queues innerObservable(C) without output.
At which step does exhaustMap start processing innerObservable(F)?
AStep 9
BStep 10
CStep 11
DStep 12
💡 Hint
Look at execution_table row 11 where exhaustMap starts innerObservable(F) after previous completes.
According to variable_tracker, how many active inner Observables does mergeMap have after step 2?
A2
B0
C1
D3
💡 Hint
See variable_tracker row for mergeMap active inner Observables after step 2.
Concept Snapshot
mergeMap: runs all inner Observables at once, outputs as they come.
concatMap: queues inner Observables, runs one at a time in order.
exhaustMap: ignores new source values while inner Observable is active.
Use mergeMap for parallel, concatMap for ordered, exhaustMap to ignore overlaps.
Full Transcript
This visual execution compares three Angular RxJS operators: mergeMap, concatMap, and exhaustMap. When the source Observable emits a value, each operator decides how to handle the inner Observable created from that value. mergeMap runs all inner Observables concurrently, emitting their results as they arrive. concatMap queues inner Observables and runs them one after another, waiting for each to complete before starting the next. exhaustMap ignores new source emissions if an inner Observable is still active, only starting a new one after the current completes. The execution table shows step-by-step how each operator behaves with source emissions and inner Observable outputs. The variable tracker highlights how many inner Observables are active or queued at key steps. Key moments clarify common confusions about queuing, ignoring, and concurrency. The visual quiz tests understanding by referencing specific steps and variable states. The snapshot summarizes when to use each operator based on concurrency and ordering needs.