SOURCE

// 结合生成器进行流处理
async function* asyncDataGenerator() {
    let moreData = true
    let page = 1
    while (moreData) {
        const data = await fetch(`https://api.example.com/data?page=${page}`)
        const response = await data.json()
        yield* response.items
        moreData = response.moreData
        page += 1
    }
}
// 调用
async function processData(){
    for await (let item of asyncDataGenerator()){
        console.log(item)
    }
}
console 命令行工具 X clear

                    
>
console