I have an async function “getResults” that performs fetch await, waits for result, then does something with the result.
If I call that async function “getResults” with 2 different parameters at the same time, wanting to fetch 2 different things, it will go ahead and perform only one of them (I guess the one that came in first)
async function getResults(id, source, destination) {
let result1 = await fetch.listen({
listen: id
}, apiHost("api.gps.com", "someparam", source)) /* this would be fetch result with parameters from getLosAngelesRoute function */
let result2 = /* here I would like to fetch with parameters from getWashingtonRoute function */
if (result1 !== result2) {
// do something
}
else {
// do nothing
}
}
function getLosAngelesRoute() {
getResults("id1", "newYork", "losAngeles")
}
function getWashingtonRoute() {
getResults("id2", "detroit", "washington")
}
The workaround fix is to have 2 different functions “getResultsA” and “getResultsB” and call them separately...
But is it possible to call function “getResults” with different parameters from functions getLosAngelesRoute and getWashingtonRoute at the same time, have it fetch await BOTH and then do something with both results all within one function?
Hope this makes sense.
Thank you for your valuable thoughts.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/uRqQXp0
Comments
Post a Comment