waitForStateOrContext blocks until the state or a greater one is reached or the provided context ends.
(ctx context.Context, state State)
| 241 | // waitForStateOrContext blocks until the state or a greater one is reached or |
| 242 | // the provided context ends. |
| 243 | func (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. |