I'm calling 4 asynchronous network functions in parallel, but I need to wait on one specific function to finish in order to continue my code.
Currently, here's what I've implemented:
async function callAllFuncs () {
// I need to call the important one as it might be delayed in the Network system if there are already too many requests pending.
// So having the important one first will be better, and might return faster than if I call it at the end
const importantPromise = fetch('/a') // No await here, as I don't want to block
fetch('/b')
fetch('/c')
fetch('/d')
return await importantPromise // Now we wait!
}
Is there a better way to do that ?
(Calling all four functions and returning as soon as the important one has finished, regardless of the three others).
Calling Promise.all
or Promise.allSettled
doesn't work here because it will wait for all functions to either finish or fail. I don't want to wait for the three others at all, I just want to return as soon as '/a' has finished, regardless of the three others.