I can't seem to figure out why the loop is executing at full speed even though the await is in the loop.
model.collection.distinct("symbol", async function (error, distSymbols) {
// iterate over the unique symbols and compute aggregate
for (const symbol of distSymbols) {
//
//await computeAggregate(model, symbol);
await dummy(Math.random() * 1000);
console.log(symbol); //This will execute before any of the dummy awaits
}
res.json("success");
});
});
const dummy = async(timeToWait) => {
setTimeout(() => {
console.log("I am waiting for", timeToWait);
return true;
}, timeToWait);
}