2 import { mergeMap } from './mergeMap';
3 import { identity } from '../util/identity';
4 import { OperatorFunction, ObservableInput } from '../types';
7 * Converts a higher-order Observable into a first-order Observable which
8 * concurrently delivers all values that are emitted on the inner Observables.
10 * <span class="informal">Flattens an Observable-of-Observables.</span>
14 * `mergeAll` subscribes to an Observable that emits Observables, also known as
15 * a higher-order Observable. Each time it observes one of these emitted inner
16 * Observables, it subscribes to that and delivers all the values from the
17 * inner Observable on the output Observable. The output Observable only
18 * completes once all inner Observables have completed. Any error delivered by
19 * a inner Observable will be immediately emitted on the output Observable.
22 * Spawn a new interval Observable for each click event, and blend their outputs as one Observable
24 * import { fromEvent, interval } from 'rxjs';
25 * import { map, mergeAll } from 'rxjs/operators';
27 * const clicks = fromEvent(document, 'click');
28 * const higherOrder = clicks.pipe(map((ev) => interval(1000)));
29 * const firstOrder = higherOrder.pipe(mergeAll());
30 * firstOrder.subscribe(x => console.log(x));
33 * Count from 0 to 9 every second for each click, but only allow 2 concurrent timers
35 * import { fromEvent, interval } from 'rxjs';
36 * import { take, map, mergeAll } from 'rxjs/operators';
38 * const clicks = fromEvent(document, 'click');
39 * const higherOrder = clicks.pipe(
40 * map((ev) => interval(1000).pipe(take(10))),
42 * const firstOrder = higherOrder.pipe(mergeAll(2));
43 * firstOrder.subscribe(x => console.log(x));
46 * @see {@link combineAll}
47 * @see {@link concatAll}
48 * @see {@link exhaust}
50 * @see {@link mergeMap}
51 * @see {@link mergeMapTo}
52 * @see {@link mergeScan}
53 * @see {@link switchAll}
54 * @see {@link switchMap}
57 * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of inner
58 * Observables being subscribed to concurrently.
59 * @return {Observable} An Observable that emits values coming from all the
60 * inner Observables emitted by the source Observable.
64 export function mergeAll<T>(concurrent: number = Number.POSITIVE_INFINITY): OperatorFunction<ObservableInput<T>, T> {
65 return mergeMap(identity, concurrent);