I am looking for a way to detect when all of the elements of my forEach have been processed.
Here is the code im using, and works as intended. All renderItem(item) are executed async.
But I want to detect when all of them are finished.
$.each(result, async function (index, item) {
await renderItem(item);
});
I have tried the following Best way to wait for .forEach() to complete
Essentially I did this:
var bar = new Promise((resolve, reject) => {
$.each(result, async function (index, item) {
await renderItem(item);
});
});
bar.then(() => {
console.log('All done!');
});
But I am not getting the console.log('All done!');
Am I doing something wrong?
Is there a better way to achieve this?