()
| 371 | |
| 372 | // Mid-stream destroy must release pending awaits so the consumer loop exits. |
| 373 | export 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. |
nothing calls this directly
no test coverage detected