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

Method waitForStateOrContext

agent/reconnectingpty/reconnectingpty.go:243–265  ·  view source on GitHub ↗

waitForStateOrContext blocks until the state or a greater one is reached or the provided context ends.

(ctx context.Context, state State)

Source from the content-addressed store, hash-verified

241// waitForStateOrContext blocks until the state or a greater one is reached or
242// the provided context ends.
243func (s *ptyState) waitForStateOrContext(ctx context.Context, state State) (State, error) {
244 s.cond.L.Lock()
245 defer s.cond.L.Unlock()
246
247 nevermind := make(chan struct{})
248 defer close(nevermind)
249 go func() {
250 select {
251 case <-ctx.Done():
252 // Wake up when the context ends.
253 s.cond.Broadcast()
254 case <-nevermind:
255 }
256 }()
257
258 for ctx.Err() == nil && state > s.state {
259 s.cond.Wait()
260 }
261 if ctx.Err() != nil {
262 return s.state, ctx.Err()
263 }
264 return s.state, s.error
265}
266
267// readConnLoop reads messages from conn and writes to ptty as needed. Blocks
268// until EOF or an error writing to ptty or reading from conn.

Callers 4

lifecycleMethod · 0.80
AttachMethod · 0.80
lifecycleMethod · 0.80
AttachMethod · 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