concatAll

signature: concatAll(): Observable

Collect observables and subscribe to next when previous completes.

:warning: Be wary of backpressure when the source emits at a faster pace than inner observables complete!

:bulb: In many cases you can use concatMap as a single operator instead!

Examples

( example tests )

Example 1: concatAll with observable

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { map, concatAll } from 'rxjs/operators';
import { of, interval } from 'rxjs';

//emit a value every 2 seconds
const source = interval(2000);
const example = source.pipe(
  //for demonstration, add 10 to and return as observable
  map(val => of(val + 10)),
  //merge values from inner observable
  concatAll()
);
//output: 'Example with Basic Observable 10', 'Example with Basic Observable 11'...
const subscribe = example.subscribe(val =>
  console.log('Example with Basic Observable:', val)
);

Example 2: concatAll with promise

( StackBlitz | jsBin | jsFiddle )

Example 3: Delay while inner observables complete

( StackBlitz | jsBin | jsFiddle )

Additional Resources

:file_folder: Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/concatAll.ts

Last updated

Was this helpful?