I have a promise which has child promise in it. when I am running the child promise which has array of urls, and mapping through each of urls to get the response but its not waiting for request to complete and moves to next iteration in parent promise.
Calling fetchProductByUrl from parent promise
let imageUrl = [primaryImage , ...productImages];
console.log("starting of fetching images");
let images = await fetchProductByUrl(imageUrl ,"image");
async function fetchProductByUrl(url_array , cfmModelName) {
try {
let promiseArray = await Promise.all(url_array.map(async (url) => {
return axios.get(url); // this is completing after all parent's iteration
})).then(res => {
return res
})
} catch (error) {
console.log(error);
return error;
}
}
Is there anything wrong in the fetchProductByUrl function. It doesnt wait for all the request and move to the next iteration in parent promise.
Tried with async and await and also axios.all. Same issue. Expecting child promise fetchProductByUrl to get all response from all array of urls and then move to next iteration in parent promise