Skip to content

Instantly share code, notes, and snippets.

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 ygnoh/fa55e4fd922bad68d7472cd69c702243 to your computer and use it in GitHub Desktop.
Save ygnoh/fa55e4fd922bad68d7472cd69c702243 to your computer and use it in GitHub Desktop.
invoking an async function multiple times in regular sequence
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