My app will make multiple parallel http call. Its based on a switch-fall though logic, so the number of query will vary (1, 2, or 3 calls). Is there a way for me to know which call gets returned first? I.e either assign a key or does it return in an ordered way based on the http request on the list?
Either way works for me. I just need to find a way to match the right result with the right call.
forkJoin accepts a variable number of observables and subscribes to them in parallel. When all of the provided observables complete, forkJoin collects the last emitted value from each and emits them as an array (this is by default, more on this later).
“If any input observable errors at some point, forkJoin will error as well and all other observables will be immediately unsubscribed.”
Yes, forkJoin will subscribe to observables in parallel, which means the requests will be executed in parallel.
forkJoin is an operator that takes any number of input observables which can be passed either as an array or a dictionary of input observables. If no input observables are provided (e.g. an empty array is passed), then the resulting stream will complete immediately.
Yes it returns the results in the same order that you make requests in an array
example,
const bothrequests= Observable.combineLatest(
this.http.get('https://testdb1.com/.json').map((res: Response) => res.json()),
this.http.get('https://testdb2.com/.json').map((res: Response) => res.json())
)
bothrequests.subscribe(latestValues => {
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With