Documentation
¶
Overview ¶
Waiting for a child's output pipes after it exits.
Ports packages/coding-agent/src/utils/child-process.ts waitForChildProcess.
Index ¶
Constants ¶
const Grace = 100 * time.Millisecond
Grace mirrors upstream EXIT_STDIO_GRACE_MS.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hooks ¶
type Hooks struct {
// BeforeRead runs in each reader before its first read.
BeforeRead func()
// GraceExpired runs when the idle grace elapses, before MayHoldOutput.
GraceExpired func()
}
Hooks order the reader, the child's exit and the grace in tests without sleeps. The zero value does nothing.
type Pipes ¶
type Pipes struct {
// contains filtered or unexported fields
}
Pipes reads a child's output pipes. Create it with Start before the child runs and call Wait once the child has exited.
func Start ¶
Start reads each file until it fails or ends, calling onData with the index of the file and the bytes read. Calls to onData never overlap, and none starts after Wait has abandoned the pipes.
func (*Pipes) Wait ¶
Wait mirrors the post-exit half of upstream waitForChildProcess: once the child has exited, keep reading until every pipe ends, or until no data has arrived on any pipe for Grace (re-armed on every chunk). A descendant that inherited a pipe therefore neither blocks the call nor truncates output it is still writing. Wait then closes the pipes, discards what a reader had not yet delivered when the grace released the wait, and returns after every reader has stopped. It reports whether every pipe ended.
The grace exists only for a descendant that still holds a pipe. When it expires, mayHoldOutput reports whether any such process can still be alive. If none can, every write end is closed, so EOF follows once the readers have drained what the child's tree already wrote, and Wait reads to EOF. Otherwise a reader that fell behind (a loaded Windows runner) would drop output the exited command had already written: the grace measures the reader's own latency, not the writer's silence.