I'm trying to work with a Promise.all() function in combination with a for loop where I chained multiple promises. When I have completed the iterations and for each iteration all my promises have been resolved I want the Promise.all() to fire.
Underneath you can find my code. According to what I've read on other fora I try to push my promises to an array which would then be used in the "Promise.all()" function. I would expect my promises to be fulfilled when when I succesfully have done the "createrows" function however the promise.all() is fulfilled even before my creatrows function is executing.
Does anyone have any idea what I might be doing wrong or which misconceptions I have around the promises framework?
for (i in scheduledRunsObjValue) {
promisearray.push(
getpropertiesObject(i,scheduledRunsObjValue).then(
propertiesObj=>{
utcDate=propertiesObj['startTime'];
localDate=new Date(utcDate);
const trackingid=propertiesObj['correlation']['clientTrackingId'];
returnhttpinputobjectforworkflow(bearertoken,trackingid).then(HttpInputObject=>{
ReturnInputHttpRequestData(HttpInputObject).then(HttpRequestData=>{
createrows(HttpRequestData,scheduledRunsHTML,i,localDate,propertiesObj,trackingid,scheduledRunsObj).then(htmldoc=>{
scheduledRunsHTML=htmldoc;
resolve(scheduledRunsHTML);
})
})
})
})
);
}
Promise.all(promisearray).then(values=>{
resolve(scheduledRunsHTML);
})