async function test() { // Regular Iterator for (const i of list) ... // Async Iterator for await (const i of Promise list) ... }
// example from: https://jakearchibald.com/2017/async-iterators-and-generators/ async function* asyncRandomNumbers() { const url = "https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new"; while (true) { const response = await fetch(url); const text = await response.text(); yield Number(text); } } (async function() { let i = 0; for await (const number of asyncRandomNumbers()) { console.log(++i, "=>", number); if (i === 10) break; } })(); // 1 "=>" 65 // 2 "=>" 62 // ...
NAVER D2
https://d2.naver.com/helloworld/4007447

Seonglae Cho