Angular · RxJS · Mid-Level · Live Coding
How would you implement a cancellable search-as-you-type with RxJS?
Short Interview Answer
Listen to input events, debounceTime, distinctUntilChanged, switchMap to HTTP.
Detailed Explanation
switchMap cancels in-flight requests when the query changes. Handle errors with catchError per inner observable so the outer stream survives.
Example
query$.pipe(
debounceTime(300),
distinctUntilChanged(),
switchMap(q => this.api.search(q).pipe(catchError(() => of([]))))
)