I have some code like this:
const main = async () => {
const timeout = () => {
return new Promise(resolve => setTimeout(resolve, 3000));
}
for (var i = 0 ; i < 5 ; i++){
await timeout()
}
return i
}
main()
I would want main to run all processes in the loop in parallell, but at the same time make sure not to return unless all processes have been completed, in other words, I will have to wait a little bit more than 3000ms, instead of 15000ms, what is the best way to achieve this?