I currently have a program where I want to call several REST API:s in parallel, but I'm only interested in the result from one of them.
Currently I've solved it like this:
private async loadData () {
const all = [this.loadFirstData(), this.loadSecondData(), this.loadThirdData()];
const combine = Promise.all(all);
await combine;
// One of the promises just puts it's return value in this global variable, so that I can access it after it is done.
if (this.valueFromThirdAPI) {
// Do something with value
}
}
So what I do is just put the put the result from the promise I want a result from in a global variable that I can access after all of the promises have returned. This works, but I'm sure there must be a much better way of doing this.
Promises.all returns a array of the resolved values, but how do I distinguish them from each other if I'm only interested in the value from one of them? The other two doesn't need to return anything.
Thanks in advance!