refactor: extract pipeIterable helper used by three emit loops
One helper in src/pipe.ts now owns the pause/resume/close wiring,
value serialization + transferable collection, and the adaptive
yield state machine. Used by:
- worker-entry.ts handleStreamTask — worker-to-parent stream emission
- execute.ts pipeToPort — parent-to-worker iterable arg piping (now
gains adaptive yield it was previously missing, fixing a latent
starvation bug if the main thread was otherwise idle)
- channel.ts Distributor.tryPull kept separate (multi-consumer
work-stealing doesn't fit the 1:1 shape) but gets the same
adaptive-yield inline for consistency
Behavioral change: pipeToPort now yields adaptively. It previously
never yielded, which was fine when the main thread had other I/O but
could starve pause delivery in pure-CPU pipelines.
Surprising side effect: extracting the worker-entry emit loop into
its own function pushed streaming throughput from ~85K items/s to
~390K items/s for a purely-synchronous generator — same logic,
much better JIT optimization once the emit loop isn't inlined in
the large handleStreamTask async function. A 4.6x win on top of
the 2.1x the adaptive-yield change already gave.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>