Last active
March 19, 2020 06:04
-
-
Save ygnoh/fa55e4fd922bad68d7472cd69c702243 to your computer and use it in GitHub Desktop.
invoking an async function multiple times in regular sequence
This file contains 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
const af = n => { | |
return new Promise(res => { | |
setTimeout(() => { | |
console.log(n); | |
res(); | |
}, 200 * n); | |
}) | |
}; | |
(async () => { | |
console.log("start"); | |
await Promise.all([0, 1, 2, 3, 4].map(async n => { | |
await af(n); | |
console.log("done: ", n); | |
})); | |
console.log("end"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment