githubEdit

concat

signature: concat(observables: ...*): Observable

Subscribe to observables in order as previous completes


💡 You can think of concat like a line at a ATM, the next transaction (subscription) cannot start until the previous completes!

💡 If throughput, not order, is a primary concern, try merge instead!


Ultimate RxJSarrow-up-right

Examples

Example 1: Basic concat usage with three observables

( StackBlitzarrow-up-right )

// RxJS v6+
import { of, concat } from 'rxjs';

concat(
  of(1, 2, 3),
  // subscribed after first completes
  of(4, 5, 6),
  // subscribed after second completes
  of(7, 8, 9)
)
  // log: 1, 2, 3, 4, 5, 6, 7, 8, 9
  .subscribe(console.log);

Example 2: Display message using concat with delayed observables

( StackBlitzarrow-up-right )

Example 2

Example 3: (Warning!) concat with source that does not complete

( StackBlitzarrow-up-right )

Additional Resources


📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/concat.tsarrow-up-right

Last updated