WaitForConnectivityState waits until the state pushed to this ClientConn matches the wanted state. Returns an error if the provided context expires, including the last received state (if any).
(ctx context.Context, want connectivity.State)
| 255 | // matches the wanted state. Returns an error if the provided context expires, |
| 256 | // including the last received state (if any). |
| 257 | func (tcc *BalancerClientConn) WaitForConnectivityState(ctx context.Context, want connectivity.State) error { |
| 258 | var lastState connectivity.State = -1 |
| 259 | for { |
| 260 | select { |
| 261 | case <-ctx.Done(): |
| 262 | return fmt.Errorf("timeout when waiting for state to be %s; last state: %s", want, lastState) |
| 263 | case s := <-tcc.NewStateCh: |
| 264 | if s == want { |
| 265 | return nil |
| 266 | } |
| 267 | lastState = s |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | // WaitForRoundRobinPicker waits for a picker that passes IsRoundRobin. Also |
| 273 | // drains the matching state channel and requires it to be READY (if an entry |