For some reason the then function is being executed before the part inside promise.all() is executed
const Uploader = async (req, res, myFunc) => {
const fileIds = req.body.fileIds;
const dataArray = [];
await Promise.all([
fileIds.forEach(fileId => {
fileServer.UploadCreds(req.user.organization.ssoId, req.user.ssoId, (err, data) => {
console.log(" in promise 1----",dataArray)
data.fileId = fileId,
dataArray.push(data)
console.log(" in promise 2----",dataArray)
});
})
]).then(()=>{
console.log(" in promise 3----",dataArray)
return myFunc(req.params.id, req.user, dataArray, apiUtils.respond(res))
})
};
I have also attempted replacing await with return, calling myFunc from inside promise all and returning that but "in promise 3" always prints with an empty array before the other two logs. I have also tried adding a catch block incase promise was failing but it wasn't.