Does the Observable.forkJoin work the same as the Observable.combineLatest
Observable.forkJoin
Observable.combineLatest
let observable1 = service.observable1(); let observable2 = service.observable2(); let observable3 = service.observable3(); let joinedObservables = forkJoin(observable1, observable2, observable3).subscribe(x => { let result1 = x[0]; let result2 = x[1]; let result3 = x[2]; }); let joinedObservables = combineLatest(observable1, observable2, observable3).subscribe(x => { let result1 = x[0]; let result2 = x[1]; let result3 = x[2]; });
runs observables in parallel, emitting a value each time an observable emits a value after all observables have emitted at least one value. combineLatest example
combineLatest
runs observables in parallel, and emits a single value once all observables have been completed. forkJoin example
forkJoin
If any of the observables error out – with combineLatest it will emit up to the point the error is thrown. forkJoin will give back an error if any of the observables fail.
Advanced note: CombineLatest doesn’t just get a single value for each source and move on to the next. If you need to ensure you only get the ‘next available item’ for each source observable you can add .pipe(take(1)) to the source observable as you add it to the input array.
CombineLatest
.pipe(take(1))