Reference

RxJS

    RxJS

    mergeAll

    mergeAll combines a number of inner observable streams and concurrently emits all values from every input stream. It’s similar to merge, but instead of taking a set of streams directly as input, it takes an observable source that produces other streams (observables). Those streams are often referred to as inner stream (observable) and the stream that emits them is known as higher-order observable.

    As values from any combined sequence are produced, those values are emitted as part of the resulting sequence. Such process is often referred to as flattening in documentation.

    Use this operator if you’re not concerned with the order of emissions and is simply interested in all values coming out from multiple combined streams as if they were produced by one stream.

    The operator works in the following way:

    1. Subscribe to the higher-order source observable
    2. When a new inner observable is emitted from the source observable, subscribe to it
    3. When a new value arrives from an inner souce observable, pass it down to an observer
    4. Only after all inner source observables complete, send the complete notification to the observer.
    5. If any of the inner source observables throws an error, send the error notification to the observer.

    In the diagram below you can see the H higher-order stream that produces two inner streams A and B. The mergeAll operator combines values from these two streams and then passes them through to the resulting sequence as they occur:

    Progress: NaN%

    Usage
    Link to this section

    Use this operator if you’re not concerned with the order of emissions and is simply interested in all values coming out from multiple combined streams as if they were produced by one stream.

    Here’s an example of using merge on multiple streams:

    <>Copy
    const a = interval(500).pipe(map((v) => 'a' + v), take(3)); const b = interval(500).pipe(map((v) => 'b' + v), take(3)); merge(a, b).subscribe((value) => console.log(value));

    Playground
    Link to this section

    Additional resources
    Link to this section

    See also
    Link to this section

    Next

    Introduction