전현진

Delete test2.js

Showing 1 changed file with 0 additions and 30 deletions
1 -const delay = () => {
2 - const randomDelay = Math.floor(Math.random() * 4) * 100
3 - return new Promise(resolve => setTimeout(resolve, randomDelay))
4 - }
5 -
6 -const loop = async (list) => {
7 -console.log("시작")
8 -const promises = list.map(async data => {
9 - return await delay()
10 - .then(() => data)
11 -})
12 -
13 -const results = await Promise.all(promises)
14 -results.forEach(data => console.log(data))
15 -console.log("끝")
16 -}
17 -
18 -const list = [1, 2, 3, 4, 5, 6, 7]
19 -loop(list)
20 -
21 -
22 -// const result = async (list) => {
23 -// for (const data of list) {
24 -// await delay()
25 -// .then(() => console.log(data))
26 -// }
27 -// }
28 -
29 -// const list = [1, 2, 3, 4, 5, 6, 7]
30 -// result(list)
...\ No newline at end of file ...\ No newline at end of file