Debian Codegraph @

node/rxjs/src/internal/operators/concatAll.ts

raw
1 import { mergeAll } from './mergeAll';
2 import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types';
3
4 /**
5 * Converts a higher-order Observable into a first-order Observable by
6 * concatenating the inner Observables in order.
7 *
8 * <span class="informal">Flattens an Observable-of-Observables by putting one
9 * inner Observable after the other.</span>
10 *
11 * ![](concatAll.svg)
12 *
13 * Joins every Observable emitted by the source (a higher-order Observable), in
14 * a serial fashion. It subscribes to each inner Observable only after the
15 * previous inner Observable has completed, and merges all of their values into
16 * the returned observable.
17 *
18 * __Warning:__ If the source Observable emits Observables quickly and
19 * endlessly, and the inner Observables it emits generally complete slower than
20 * the source emits, you can run into memory issues as the incoming Observables
21 * collect in an unbounded buffer.
22 *
23 * Note: `concatAll` is equivalent to `mergeAll` with concurrency parameter set
24 * to `1`.
25 *
26 * ## Example
27 *
28 * For each click event, tick every second from 0 to 3, with no concurrency
29 *
30 * ```ts
31 * import { fromEvent, map, interval, take, concatAll } from 'rxjs';
32 *
33 * const clicks = fromEvent(document, 'click');
34 * const higherOrder = clicks.pipe(
35 * map(() => interval(1000).pipe(take(4)))
36 * );
37 * const firstOrder = higherOrder.pipe(concatAll());
38 * firstOrder.subscribe(x => console.log(x));
39 *
40 * // Results in the following:
41 * // (results are not concurrent)
42 * // For every click on the "document" it will emit values 0 to 3 spaced
43 * // on a 1000ms interval
44 * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
45 * ```
46 *
47 * @see {@link combineLatestAll}
48 * @see {@link concat}
49 * @see {@link concatMap}
50 * @see {@link concatMapTo}
51 * @see {@link exhaustAll}
52 * @see {@link mergeAll}
53 * @see {@link switchAll}
54 * @see {@link switchMap}
55 * @see {@link zipAll}
56 *
57 * @return A function that returns an Observable emitting values from all the
58 * inner Observables concatenated.
59 */
60 export function concatAll<O extends ObservableInput<any>>(): OperatorFunction<O, ObservedValueOf<O>> {
61 return mergeAll(1);
62 }