MCPcopy Index your code
hub / github.com/coder/coder / waitForOutput

Method waitForOutput

agent/agentproc/process.go:340–365  ·  view source on GitHub ↗

waitForOutput blocks until the buffer is closed (process exited) or the context is canceled. Returns nil when the buffer closed, ctx.Err() when the context expired.

(ctx context.Context)

Source from the content-addressed store, hash-verified

338// exited) or the context is canceled. Returns nil when the
339// buffer closed, ctx.Err() when the context expired.
340func (p *process) waitForOutput(ctx context.Context) error {
341 p.buf.cond.L.Lock()
342 defer p.buf.cond.L.Unlock()
343
344 nevermind := make(chan struct{})
345 defer close(nevermind)
346 go func() {
347 select {
348 case <-ctx.Done():
349 // Acquire the lock before broadcasting to
350 // guarantee the waiter has entered cond.Wait()
351 // (which atomically releases the lock).
352 // Without this, a Broadcast between the loop
353 // predicate check and cond.Wait() is lost.
354 p.buf.cond.L.Lock()
355 defer p.buf.cond.L.Unlock()
356 p.buf.cond.Broadcast()
357 case <-nevermind:
358 }
359 }()
360
361 for ctx.Err() == nil && !p.buf.closed {
362 p.buf.cond.Wait()
363 }
364 return ctx.Err()
365}
366
367// resolveWorkDir returns the directory a process should start in.
368// Priority: explicit request dir > agent configured dir > $HOME.

Callers 1

handleProcessOutputMethod · 0.80

Calls 5

ErrMethod · 0.80
WaitMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected