I am trying to process all images in an array and push all of the processed images in other array.
The processing stuff runs async, so I am using await Promise.all to wait until all of the images has been processed. Anyways, the array is undefined when the code finishs.
Here is what I am doing:
async function processImage(image) {
// ... stuff
return new Promise((resolve, reject) => {
(async () => {
// Validate each image uploaded by the user
const images = await Promise.all( // <--------------------------------
imagesIds.map(async (id) => {
// ... async stuff
if(!error)
return processedImage; // <-------------------------------
else {
reject(error);
}
}
}
// ... stuff
console.log(images); <-------- undefined
resolve();
})();
}
Any ideas what I am doing wrong? Thanks.