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