ReferencetakeUntil
Reference · 15
takeUntil
takeUntil
The stream lives until notifier$ emits its first value.
Signature
takeUntil(notifier: ObservableInput): MonoTypeOperatorFunction
Marble diagram
in: --1--2--3--4--|
notifier: --------n----
result: --1--2--|
What it does
Subscribes to notifier$ in parallel. On its first next, it sends complete to the main stream and unsubscribes from both. If notifier$ completes without emitting, the main stream keeps living.
When to use
The standard way to unsubscribe in Angular: destroy$ = new Subject() in the component, destroy$.next() in ngOnDestroy. Also: cancelling a request on navigation, timeouts with an independent trigger.
Gotcha
takeUntil should come last in the pipe — otherwise operators after it (shareReplay, for example) can keep the subscription alive.
See also
take, takeWhile, finalize
script.ts
CONSOLE · Console output
Hit Run to see the result...