mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-31 07:23:06 +08:00
Under the synchronous output model nothing is ever queued: Node emits 'drain' only after a write() returned false, and these writes never return false. The process streams therefore describe a stream whose writes complete synchronously, and the members a flush idiom probes are constants: - writableHighWaterMark is 65536 (Node's default for a pipe, a file and a TTY); - writableNeedDrain is false; - writableLength stays 0. `on`/`once`/`addListener`/`off`/`removeListener`/`prependListener`/ `prependOnceListener` of "drain" evaluate their receiver and listener and register nothing: the event cannot fire, and the listener table is not observable (listenerCount/listeners/eventNames on the process streams stay refused). `events.once(process.stdout | process.stderr, "drain")` lowers to `events.pendingForever`, a fresh promise that never settles, which is Node's behavior for a stream no write asked to drain; it holds no loop handle, so a program awaiting it still exits. The fallback declarations gain writableHighWaterMark, writableNeedDrain and the event methods, so typed programs can ask. Corpus: `tests/corpus/process-stream-drain.ts`; the diagnostics fixture `process-stream-listener-count.ts` pins that reading the listener table stays refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>