Skip to content

Instantly share code, notes, and snippets.

@ariona
Created July 18, 2020 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariona/cabd991a97522cae9d9e4cd7be152df3 to your computer and use it in GitHub Desktop.
Save ariona/cabd991a97522cae9d9e4cd7be152df3 to your computer and use it in GitHub Desktop.
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