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

Method WaitForCond

testutil/wait_buffer.go:71–90  ·  view source on GitHub ↗

WaitForCond blocks until cond returns true for the accumulated output, or ctx expires. Returns nil on match, ctx.Err() on timeout. Safe to call from any goroutine.

(ctx context.Context, cond func(string) bool)

Source from the content-addressed store, hash-verified

69// output, or ctx expires. Returns nil on match, ctx.Err() on
70// timeout. Safe to call from any goroutine.
71func (wb *WaitBuffer) WaitForCond(ctx context.Context, cond func(string) bool) error {
72 wb.mu.Lock()
73 if cond(wb.buf.String()) {
74 wb.mu.Unlock()
75 return nil
76 }
77 w := &wbWaiter{
78 cond: cond,
79 ch: make(chan struct{}),
80 }
81 wb.waiters = append(wb.waiters, w)
82 wb.mu.Unlock()
83
84 select {
85 case <-w.ch:
86 return nil
87 case <-ctx.Done():
88 return ctx.Err()
89 }
90}
91
92// RequireWaitFor blocks until the accumulated output contains
93// signal or ctx expires. On timeout, fails the test with a

Callers 2

WaitForNthMethod · 0.95

Calls 5

ErrMethod · 0.80
LockMethod · 0.45
StringMethod · 0.45
UnlockMethod · 0.45
DoneMethod · 0.45

Tested by 1