概述desiredSize 反映队列高水位与背压情况。本文示例按需生产数据。调优示例function generateStream(total = 10, chunkSize = 1024) { let produced = 0; return new ReadableStream({ async pull(controller) { const ds = controller.desiredSize; if (ds <= 0) return; // 背压:暂不生产 if (produced >= total) { controller.close(); return; } const chunk = new Uint8Array(chunkSize); controller.enqueue(chunk); produced++; } }); }

发表评论 取消回复