[grpc-go] ClientConn exposes WaitForConnection API

12 views
Skip to first unread message

yishu

unread,
Jun 7, 2023, 10:00:40 PM6/7/23
to grpc.io
Hey grpc community,
I am sorry if it's been asked. I did a very short research and didn't find the answer. 

Is it possible for ClientConn to expose a WaitForConnection API that blocks until connectivity becomes READY? something like
```
func (cc *ClientConn) WaitForConnection(cc *grpc.ClientConn, deadline time.Time) {
    ctx := context.Background()
    if deadline != time.Time{} {
        var cancel context.CancelFunc
        ctx, cancel = context.WithDeadline(ctx, deadline)
        defer cancel()
    }
    for {
        state := cc.GetState()
        if state == connectivity.Ready {
            return
        }
        if !cc.WaitForStateChange(ctx, state) {
            return
        }
    }
}
```
yishu

--
戴翊書
Yi-Shu Tai
Software Engineer @Dropbox
Reply all
Reply to author
Forward
0 new messages