concatAll
Last updated
Last updated
concatAll(): Observable
⚠ Be wary of backpressure when the source emits at a faster pace than inner observables complete!
💡 In many cases you can use concatMap as a single operator instead!
concatAll
?This operator is best used when you have multiple observables that need to be processed sequentially, ensuring that each observable completes before moving on to the next. Real-world examples of this can be seen in scenarios such as uploading multiple files to a server one-by-one, or displaying a sequence of animations in order.
Bear in mind that concatAll
will only start processing the next observable when the current one completes. This is an important consideration if you have observables that emit values indefinitely or take a long time to complete, as it may cause a delay in processing subsequent observables.
Additionally, if you're working with observables that can emit values concurrently and don't need to wait for one to complete before processing another, mergeAll might be a more suitable choice. Similarly, if you only need to combine the values of multiple observables at the point when they all complete, forkJoin could be a better option.
( example tests )
Example 1: concatAll with observable
( StackBlitz | jsBin | jsFiddle )
Example 2: concatAll with promise
( StackBlitz | jsBin | jsFiddle )
Example 3: Delay while inner observables complete
( StackBlitz | jsBin | jsFiddle )
concatAll 📰 - Official docs
concatAll - In Depth Dev Reference
Flatten a higher order observable with concatAll in RxJS 🎥 💵 - André Staltz
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/concatAll.ts