本文整理汇总了Golang中github.com/coreos/etcd/etcdserver/etcdserverpb.Watch_WatchClient.CloseSend方法的典型用法代码示例。如果您正苦于以下问题:Golang Watch_WatchClient.CloseSend方法的具体用法?Golang Watch_WatchClient.CloseSend怎么用?Golang Watch_WatchClient.CloseSend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/etcd/etcdserver/etcdserverpb.Watch_WatchClient
的用法示例。
在下文中一共展示了Watch_WatchClient.CloseSend方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WaitResponse
// WaitResponse waits on the given stream for given duration.
// If there is no more events, true and a nil response will be
// returned closing the WatchClient stream. Or the response will
// be returned.
func WaitResponse(wc pb.Watch_WatchClient, timeout time.Duration) (bool, *pb.WatchResponse) {
rCh := make(chan *pb.WatchResponse)
go func() {
resp, _ := wc.Recv()
rCh <- resp
}()
select {
case nr := <-rCh:
return false, nr
case <-time.After(timeout):
}
wc.CloseSend()
rv, ok := <-rCh
if rv != nil || !ok {
return false, rv
}
return true, nil
}
示例2: waitResponse
// waitResponse waits on the given stream for given duration.
// If there is no more events, true and a nil response will be
// returned closing the WatchClient stream. Or the response will
// be returned.
func waitResponse(wc pb.Watch_WatchClient, timeout time.Duration) (bool, *pb.WatchResponse) {
rCh := make(chan *pb.WatchResponse, 1)
donec := make(chan struct{})
defer close(donec)
go func() {
resp, _ := wc.Recv()
select {
case rCh <- resp:
case <-donec:
}
}()
select {
case nr := <-rCh:
return false, nr
case <-time.After(timeout):
}
// didn't get response
wc.CloseSend()
return true, nil
}