Rxjs: Observable.combineLatest vs Observable.forkJoin

Tuong Le picture Tuong Le · Jan 23, 2017 · Viewed 28.8k times · Source

Just wonder what is differences between Observable.combineLatest and Observable.forkJoin? As far as I can see, the only difference is forkJoin expects the Observables to be completed, while combineLatest return the latest values.

Answer

GregL picture GregL · Jan 23, 2017

Not only does forkJoin require all input observables to be completed, but it also returns an observable that produces a single value that is an array of the last values produced by the input observables. In other words, it waits until the last input observable completes, and then produces a single value and completes.

In contrast, combineLatest returns an Observable that produces a new value every time the input observables do, once all input observables have produced at least one value. This means it could have infinite values and may not complete. It also means that the input observables don't have to complete before producing a value.