Bird
0
0

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?

hard🚀 Application Q15 of 15
Angular - RxJS Operators
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?
searchInput$.pipe(
  ???(query => performSearch(query))
).subscribe(results => display(results));
A<code>exhaustMap</code> because it ignores new searches while one is running
B<code>concatMap</code> because it queues searches and runs them one by one
C<code>mergeMap</code> because it runs all searches simultaneously
D<code>switchMap</code> because it cancels previous searches on new input
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    The user wants to ignore new search inputs while a search is running, preventing duplicates.
  2. Step 2: Match operator behavior

    exhaustMap ignores new inner observables if one is active, perfect for this use case. mergeMap runs all, concatMap queues, switchMap cancels previous.
  3. Final Answer:

    exhaustMap because it ignores new searches while one is running -> Option A
  4. Quick Check:

    Ignore new inputs during active task = exhaustMap [OK]
Quick Trick: Ignore new tasks while running = exhaustMap [OK]
Common Mistakes:
MISTAKES
  • Choosing switchMap which cancels previous instead of ignoring
  • Using mergeMap which runs all searches simultaneously
  • Using concatMap which queues instead of ignoring

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes