0
I have an array where I want to execute each item, but one can only start after finishing the previous one. The example below is printing in sequence 2000,5000,10000 which makes me understand that the three items were executed simultaneously. I would like each item to start only after the completion of the previous one. I was hoping it would be printed 10000,5000,2000.
const durations = [10000, 5000, 2000]
const timeOut = (t) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(t)
resolve(true)
}, t)
})
}
for (let index = 0; index < durations.length; index++) {
const element = durations[index];
timeOut(element);
}
Thanks!! His reply helped me a lot to solve the API call I was making, and all were being done in parallel, without respecting the array sequence. Thank you.
– Ricardo