批处理
🌐 Batching
每次迭代会产生一个 批次 —— 一个 <Array> 的 <Uint8Array> 块(<Uint8Array[]>)。批处理可以将 await 和 <Promise> 的创建成本在多个块之间分摊。一个一次处理一个块的消费者可以直接迭代内部数组:
🌐 Each iteration yields a batch -- an <Array> of <Uint8Array> chunks
(<Uint8Array[]>). Batching amortizes the cost of await and <Promise> creation
across multiple chunks. A consumer that processes one chunk at a time can
simply iterate the inner array:
for await (const batch of source) {
for (const chunk of batch) {
handle(chunk);
}
}async function run() {
for await (const batch of source) {
for (const chunk of batch) {
handle(chunk);
}
}
}