Appearance
Flow Diagram
Appearance
Emits values from the source Observable until a notifier Observable emits, then completes — the primary tool for preventing memory leaks.
takeUntil<T>(notifier: ObservableInput<any>): MonoTypeOperatorFunction<T>source: --1--2--3--4--5--|
notifier: -----------n-----|
takeUntil(notifier)
result: --1--2--3--|
import { interval, Subject } from 'rxjs'
import { takeUntil } from 'rxjs/operators'
const destroy$ = new Subject<void>()
interval(1000).pipe(
takeUntil(destroy$)
).subscribe(console.log)
// In Vue: onUnmounted(() => destroy$.next())
// Subscription auto-cancels when component unmounts