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)
| 338 | // exited) or the context is canceled. Returns nil when the |
| 339 | // buffer closed, ctx.Err() when the context expired. |
| 340 | func (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. |