Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rchaser53/aae739daf10ca2782867f120f953fb98 to your computer and use it in GitHub Desktop.
Save rchaser53/aae739daf10ca2782867f120f953fb98 to your computer and use it in GitHub Desktop.
const promiseFunc = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 2000)
})
}
const forEachAsync = () => {
[1, 2, 3, 4, 5].forEach(async (index) => {
console.log(`${index} start!`)
await promiseFunc();
console.log(`${index} finish!`)
});
}
const forAsync = async () => {
for(let i=0;i<5;i++) {
console.log(`for ${i} start!`)
await promiseFunc();
console.log(`for ${i} finish!`)
}
}
forEachAsync();
forAsync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment