MCPcopy
hub / github.com/rvagg/through2 / asyncgenDestroyMidStream

Function asyncgenDestroyMidStream

test/test.js:373–385  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

371
372// Mid-stream destroy must release pending awaits so the consumer loop exits.
373export async function asyncgenDestroyMidStream () {
374 const t = objectTransform(async function * (source) {
375 for await (const x of source) { yield x; yield x }
376 })
377 const seen = []
378 t.on('data', (d) => {
379 seen.push(d)
380 if (seen.length === 2) t.destroy()
381 })
382 t.write(1); t.write(2); t.write(3)
383 await new Promise((resolve) => t.once('close', resolve))
384 ok(seen.length >= 2)
385}
386
387// Destroy must finalize the user's async generator: its `finally` block
388// must run so resources (file handles, subscriptions, etc.) can be released.

Callers

nothing calls this directly

Calls 2

objectTransformFunction · 0.90
okFunction · 0.85

Tested by

no test coverage detected