I have a delay function that goes like
const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
Inside a for each I am trying to wait X seconds (Where x is a random number coming from randomIntFromInterval
but it seems to execute all my code at once
function randomIntFromInterval(min: number, max: number) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}
const array = ['aa', 'bb', 'cc']
array.forEach(
async (item) => {
const randomTimer = randomIntFromInterval(40000, 90000);
// EXTRA LOGIC HERE
await delay(randomTimer); // THIS IS NOT WAITING PROPERLY
}
)