I've the following code which use async to get data from two functions which is call to some back-end to get data, the code works.
async function ac(token, gl) {
for (const acc of gl) {
let subsReqEu = sub(token, acc.guid, reg.1);
let subsReqUs = sub(token, acc.guid, reg.2);
// run both function async in parallel go get data from the backend
const [se, su] = await Promise.all([axios(subsRE), axios(subsRU)])
// here I got the response from the promise and should loop on it got get URL
for (const sub of se.data.sub) {
if (sub.url) {
return sub.url
}
}
// the same for the second response of the promise all
for (const sub of su.data.sub) {
if (sub.url) {
return sub.url
}
}
}
The await
Promise.all
return the data. Now I need to loop on each of the returned value
and find url
and exit from the function, currently the loops are running in sequence,(assume I've Thousands of data one each loops) how should I run them im parallel (the two for
statement) , as the first get result (url) will return the function with the value