I have an array called imagesToUpload
. Uploading function returns a promise. Right now I have to wait, images upload by one after another. This is my sample code.
function uploadTos3Bucket(filename){
return new Promise((resolve,reject)=>{
resolve(filename+'.png')
})
}
const imagesToUpload = ['Homer','Bart','Lisa','Millhouse'];
async function controller() {
const links = []
for (const imageFile of imagesToUpload) {
const link = await uploadTos3Bucket(imageFile);
links.push(link)
}
console.log('links',links)
}
controller();
Instead of this I want something where I pass the images array. Images upload parallel. Once all finished I get the links array. Of-cause I know the concept of Promise.all()
This is not what I want.
const [image1,image2] = await Promise.all([uploadTos3Bucket('Homer'),uploadTos3Bucket('Bart')])
I don't want assign to so many variables. I just want an array with all the links and most importantly if some image failed to upload, it should ignore and not break the entire process.