Created
October 11, 2019 06:23
-
-
Save rchaser53/aae739daf10ca2782867f120f953fb98 to your computer and use it in GitHub Desktop.
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
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