WEB APIS › STREAMS API
Backpressure
When a stream's internal queue fills up, the readable side signals the source to slow down. This mechanism is called backpressure, and it keeps memory usage bounded when the consumer cannot keep up with the producer.
const reader = stream.getReader();
while (true) {
const { value, done } = await reader.read();
if (done) break;
await sink.write(value); // 自动遵循 backpressure
}反压。下游处理不过来时向上游传递的减速信号,用来让缓冲区不会无限增长。