Skip to content

Instantly share code, notes, and snippets.

@ariona
Created Jul 18, 2020
Embed
What would you like to do?
Async function inside loop
(async () => {
await Promise.all(Array.from(
{ length: 5 },
(_, i) => new Promise(res => setTimeout(() => {
console.log(i);
res();
}, i * 1000))
));
console.log("loop/timeout is done executing");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment