func waitForConnection(conn *grpc.ClientConn) error { state := conn.State() var err error if state != grpc.Ready { for { if !conn.WaitForStateChange(1*time.Second, conn.State()) { err = errors.New("connection") } state := conn.State() if state == grpc.Connecting || state == grpc.Idle { continue } else if state == grpc.TransientFailure { err = errors.New("fail") } break } } return err }