MCPcopy Create free account
hub / github.com/rvagg/through2 / asyncgenReaderBackpressure

Function asyncgenReaderBackpressure

test/web.js:174–191  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

172// Downstream backpressure: a fast generator emitting many chunks, with a
173// slow reader, must not flood the readable buffer unboundedly.
174export async function asyncgenReaderBackpressure () {
175 const ts = transform(async function * (source) {
176 // eslint-disable-next-line no-unused-vars
177 for await (const _ of source) for (let i = 0; i < 50; i++) yield i
178 })
179 const r = new ReadableStream({
180 start (controller) { controller.enqueue('go'); controller.close() }
181 })
182 const reader = r.pipeThrough(ts).getReader()
183 const out = []
184 while (true) {
185 const { value, done } = await reader.read()
186 if (done) break
187 out.push(value)
188 await new Promise((resolve) => setTimeout(resolve, 1)) // slow reader
189 }
190 deepEq(out, Array.from({ length: 50 }, (_, i) => i))
191}

Callers

nothing calls this directly

Calls 2

transformFunction · 0.90
deepEqFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…