exhaustMap

Projects each source value to an Observable which is merged in the output Observable only if the previous projected Observable has completed.

exhaustMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector?: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, ObservedValueOf<O> | R>

Parameters

project

A function that, when applied to an item emitted by the source Observable, returns an Observable.

resultSelector

Optional. Default is undefined.

Type: (outerValue: T, innerValue: ObservedValueOf, outerIndex: number, innerIndex: number) => R.

Returns

OperatorFunction<T, ObservedValueOf<O> | R>: An Observable containing projected Observables of each item of the source, ignoring projected Observables that start before their preceding Observable has completed.

Description

Maps each value to an Observable, then flattens all of these inner Observables using exhaust.

Returns an Observable that emits items based on applying a function that you supply to each item emitted by the source Observable, where that function returns an (so-called "inner") Observable. When it projects a source value to an Observable, the output Observable begins emitting the items emitted by that projected Observable. However, exhaustMap ignores every new projected Observable if the previous projected Observable has not yet completed. Once that one completes, it will accept and flatten the next projected Observable and repeat this process.

Example

Run a finite timer for each click, only if there is no currently active timer

import { fromEvent, } from 'rxjs'; import { exhaustMap, take } from 'rxjs/operators'; const clicks = fromEvent(document, 'click'); const result = clicks.pipe( exhaustMap((ev) => interval(1000).pipe(take(5))), ); result.subscribe(x => console.log(x));

Overloads

exhaustMap(project: (value: T, index: number) => O): OperatorFunction<T, ObservedValueOf<O>>

Parameters

project

Type: (value: T, index: number) => O.

Returns

OperatorFunction<T, ObservedValueOf<O>>

exhaustMap(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>

Parameters

project

Type: (value: T, index: number) => O.

resultSelector

Type: undefined.

Returns

OperatorFunction<T, ObservedValueOf<O>>

exhaustMap(project: (value: T, index: number) => ObservableInput<I>, resultSelector: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>

Parameters

project

Type: (value: T, index: number) => ObservableInput.

resultSelector

Type: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R.

Returns

OperatorFunction<T, R>

See Also