Published
Edited
May 7, 2020
1 star
Insert cell
md`# exhaustMap`
Insert cell
import { of, from, tap, delay, exhaustMap } from '@egman24/rxjs-6-5-5'
Insert cell
md`
- https://learnrxjs.io/learn-rxjs/operators/transformation/exhaustmap
- https://rxjs.dev/api/operators/exhaustMap
- https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/exhaustMap.ts
`
Insert cell
md`

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

_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.

`
Insert cell
mutable thing = []
Insert cell
from(['a', 'b', 'c']).pipe(
//exhaustMap(x => of(x)),
//exhaustMap(x => of(x).pipe(delay(0))),
tap(x => { mutable thing = mutable thing.concat([x]) })
).subscribe()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more