Skip to main content

Overview

Emits the values emitted by the source Observable until a notifier Observable emits a value.
takeUntil subscribes and begins mirroring the source Observable. It also monitors a second Observable that you provide. If the notifier emits a value, the output Observable stops mirroring the source Observable and completes.

Type Signature

function takeUntil<T>(notifier: ObservableInput<any>): MonoTypeOperatorFunction<T>

Parameters

notifier
ObservableInput<any>
required
The ObservableInput whose first emitted value will cause the output Observable to stop emitting values from the source Observable.

Returns

MonoTypeOperatorFunction<T> - A function that returns an Observable that emits the values from the source Observable until notifier emits its first value.

Usage Examples

Basic Example

import { interval, fromEvent, takeUntil } from 'rxjs';

const source = interval(1000);
const clicks = fromEvent(document, 'click');
const result = source.pipe(takeUntil(clicks));

result.subscribe(x => console.log(x));
// Emits until first click
  • take - Takes first N values
  • takeLast - Takes last N values
  • takeWhile - Takes while condition is true
  • skipUntil - Skips until another Observable emits