전현진

Delete test2.js

Showing 1 changed file with 0 additions and 30 deletions
const delay = () => {
const randomDelay = Math.floor(Math.random() * 4) * 100
return new Promise(resolve => setTimeout(resolve, randomDelay))
}
const loop = async (list) => {
console.log("시작")
const promises = list.map(async data => {
return await delay()
.then(() => data)
})
const results = await Promise.all(promises)
results.forEach(data => console.log(data))
console.log("끝")
}
const list = [1, 2, 3, 4, 5, 6, 7]
loop(list)
// const result = async (list) => {
// for (const data of list) {
// await delay()
// .then(() => console.log(data))
// }
// }
// const list = [1, 2, 3, 4, 5, 6, 7]
// result(list)
\ No newline at end of file