switchMap inner observable completion timing during concurrent emissions
26K reputation · 18 Jan 2026, 18:31 UTC
Managing Inner Stream Lifecycle
In RxJS 6+, the switchMap operator is used to manage asynchronous race conditions by cancelling previous inner subscriptions when a new value arrives from the source. This prevents outdated notifications from reaching the observer.
A design uncertainty exists regarding the precise timing of completion signals when an inner observable is cancelled. Specifically, when a new emission triggers a switch, the interaction between the cancellation of the previous inner observable and the immediate subscription to the new one can create ambiguity in stream state tracking.
Given a high-frequency emission environment, how does RxJS handle the sequence of the cancellation signal relative to the new subscription? Does the previous inner observable receive a completion signal before the new observable begins emitting?