When working with data streams, we might want to combine multiple data streams into one stream to be able to get one result in some scenarios.
Majorly used combination operators are
Three scenario when we want to use combination operators can be:
The combineLatest operator is one of the combination operators that emits the last value from each of the observable streams when the observable emits a value.
You won’t see the result until each of the streams have emitted at least one value.
What happens if one of the observable didn’t complete?
Well, the output observable won’t complete too
When the observable emits only one value or you want only the last value from each stream, that is when forkJoin proves to be of help. forkJoin allows creation of the output stream with the last values from all the input streams.
When we are dealing with multiple API calls, and do not want to render the view until all the http requests have completed, forkJoin is the right thing to do.
However, you might end up in a trouble if you choose to use forkJoin when one of the input streams might not complete.
This is a pipe-able operator which creates an output stream with the latest values from the other input streams only once each of the streams have emitted at least one value.
Now I was confused about the difference between the combineLatest operator and the withLatestFrom since both of these emit the latest values. But the point of differences are:
does not wait for each of the input streams to emit at least one value.
only emits once all the input streams have emitted one value each.
Quick Links
Legal Stuff