childwait

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Waiting for a child's output pipes after it exits.

Ports packages/coding-agent/src/utils/child-process.ts waitForChildProcess.

Index

Constants

View Source
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

func Start(files []*os.File, onData func(index int, chunk []byte), hooks Hooks) *Pipes

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. The chunk is lent for the call: each pipe reads into one buffer of its own, so onData copies what it keeps.

func (*Pipes) Wait

func (p *Pipes) Wait(mayHoldOutput func() bool) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL