async function* asyncGen() {
for (let i = 0; i < 5; i++) yield i
}
async function asyncFun() {
const ag = asyncGen()
console.log(ag) // Object [AsyncGenerator] {}
console.log(ag.next()) // Promise { <pending> }
console.log(await ag.next()) // { value: 1, done: false }
for await (const v of ag) console.log(v)
// 2
// 3
// 4
return 'done'
}
asyncFun().then(v => console.log(v)) // done
그만 알아보자
왜 스트림 놔두고 이상한걸 만들었을까
그래야 한발씩 먼저 나오는 라이벌(?) 파이썬의 async generator와 균형을 맞출수가..