I have been attempting to run a loop where a promise and its respective then method are created for each iteration. My goal is to only print 'Done' once all promises have been executed in order. However, no matter what I try, 'done' always gets executed before the 'rendering's! I understand that this may seem like a repetitive issue, but so far, none of the solutions have worked. Could it be that adding a promise and a then for each iteration is causing the problem?
let p = Promise.resolve<void>()
for (let i = 0; i < data.results.length; i++) {
p = p.then(_ => template.instantiateToElement(data.results[i]).then(res => {
console.log('rendering');
}));
};
p.then(_ => {
console.log('done');
});
** template.instantiateToElement() returns a promise