mergeMap subscribes to all inner observables as they come and merges their outputs into one observable. It runs all inner streams concurrently.
Click to reveal answer
beginner
How does concatMap handle multiple inner observables?
concatMap queues inner observables and subscribes to them one by one. It waits for the current inner observable to complete before starting the next.
Click to reveal answer
intermediate
Explain exhaustMap behavior in Angular RxJS.
exhaustMap ignores new inner observables if one is already running. It only subscribes to the first inner observable and ignores others until it completes.
Click to reveal answer
intermediate
When should you use concatMap instead of mergeMap?
Use concatMap when order matters and you want to process inner observables one at a time, avoiding concurrency.
Click to reveal answer
intermediate
What is a real-life example for using exhaustMap?
exhaustMap is useful for ignoring repeated button clicks that trigger HTTP requests until the first request finishes, preventing duplicate calls.
Click to reveal answer
Which operator runs all inner observables at the same time?
AmergeMap
BconcatMap
CexhaustMap
DswitchMap
✗ Incorrect
mergeMap subscribes to all inner observables concurrently, merging their outputs.
Which operator queues inner observables and runs them one after another?
AmergeMap
BconcatMap
CexhaustMap
DswitchMap
✗ Incorrect
concatMap waits for each inner observable to complete before starting the next.
Which operator ignores new inner observables if one is already active?
AmergeMap
BconcatMap
CexhaustMap
DswitchMap
✗ Incorrect
exhaustMap ignores new inner observables until the current one completes.
If you want to prevent multiple HTTP calls from rapid clicks, which operator is best?
AexhaustMap
BmergeMap
CconcatMap
DswitchMap
✗ Incorrect
exhaustMap ignores new triggers while the first HTTP call is running.
Which operator preserves the order of inner observables?
Describe the main difference between mergeMap, concatMap, and exhaustMap in Angular RxJS.
Think about how each operator handles multiple inner streams.
You got /3 concepts.
Give an example scenario where using exhaustMap is better than mergeMap or concatMap.
Consider user actions that should not trigger repeated processes.
You got /3 concepts.
Practice
(1/5)
1. Which RxJS operator runs all inner tasks at the same time and emits results as they complete, without waiting for order?
easy
A. switchMap
B. concatMap
C. exhaustMap
D. mergeMap
Solution
Step 1: Understand mergeMap behavior
mergeMap subscribes to all inner observables immediately and merges their outputs as they arrive.
Step 2: Compare with other operators
concatMap waits for each inner observable to complete before starting the next, exhaustMap ignores new inner observables if one is active, and switchMap cancels previous inner observables.
Final Answer:
mergeMap -> Option D
Quick Check:
Runs all tasks at once = mergeMap [OK]
Hint: All tasks at once means mergeMap [OK]
Common Mistakes:
Confusing concatMap with mergeMap because both handle multiple tasks
Thinking exhaustMap runs all tasks simultaneously
Mixing switchMap behavior with mergeMap
2. Which of the following is the correct syntax to use concatMap in an Angular RxJS pipe?
easy
A. concatMap(source$, value => inner$)
B. source$.pipe(concatMap(value => inner$))
C. source$.concatMap(value => inner$)
D. source$.pipe(map(concatMap(value => inner$)))
Solution
Step 1: Recall RxJS pipe usage
Operators like concatMap are used inside pipe() method on observables.
Step 2: Check syntax correctness
source$.pipe(concatMap(value => inner$)) correctly uses source$.pipe(concatMap(...)). Options A and B misuse method chaining or function call. source$.pipe(map(concatMap(value => inner$))) wrongly nests concatMap inside map.
Final Answer:
source$.pipe(concatMap(value => inner$)) -> Option B
Quick Check:
Use pipe with concatMap inside [OK]
Hint: Always use pipe() with concatMap inside [OK]
Common Mistakes:
Calling concatMap directly on observable without pipe
Passing concatMap as argument to map
Using concatMap as a standalone function
3. Given the code below, what will be the output order of emitted values?
import { of } from 'rxjs';
import { concatMap, delay } from 'rxjs/operators';
of(1, 2, 3).pipe(
concatMap(x => of(x).pipe(delay(100 - x * 10)))
).subscribe(console.log);
medium
A. [3, 2, 1]
B. [1, 3, 2]
C. [1, 2, 3]
D. [2, 1, 3]
Solution
Step 1: Understand concatMap behavior with delays
concatMap waits for each inner observable to complete before starting the next, preserving order.
Step 2: Analyze delays and emission order
Even though delays differ (90ms, 80ms, 70ms), concatMap queues them and emits in source order: 1, then 2, then 3.
Final Answer:
[1, 2, 3] -> Option C
Quick Check:
concatMap preserves order despite delays [OK]
Hint: concatMap keeps order even if inner delays differ [OK]
Common Mistakes:
Assuming output order matches delay times
Confusing concatMap with mergeMap behavior
Ignoring that concatMap queues inner observables
4. You have this code snippet using exhaustMap. It should ignore new clicks while processing, but it processes all clicks anyway. What is the likely mistake?
A. fetchData() returns a promise, not an observable
B. Using exhaustMap instead of mergeMap
C. Not subscribing to the observable
D. Not returning an observable inside exhaustMap
Solution
Step 1: Check exhaustMap inner function return type
exhaustMap expects the function to return an observable. If fetchData() returns a promise, it won't behave correctly.
Step 2: Understand effect of returning a promise
Promises are not cancellable observables, so exhaustMap can't ignore new clicks properly, causing all clicks to process.
Final Answer:
fetchData() returns a promise, not an observable -> Option A
Quick Check:
exhaustMap needs observables, not promises [OK]
Hint: exhaustMap requires observables, not promises [OK]
Common Mistakes:
Thinking exhaustMap works with promises automatically
Forgetting to subscribe to the observable
Confusing exhaustMap with mergeMap usage
5. You want to handle user search input so that if a search is running, new inputs are ignored until it finishes. Which operator should you use and why?