Created
July 18, 2020 12:45
-
-
Save ariona/cabd991a97522cae9d9e4cd7be152df3 to your computer and use it in GitHub Desktop.
Async function inside loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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