當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Watch_WatchClient.CloseSend方法代碼示例

本文整理匯總了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
}
開發者ID:lijianwei123,項目名稱:etcd,代碼行數:22,代碼來源:v3_grpc_test.go

示例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
}
開發者ID:hongchaodeng,項目名稱:etcd,代碼行數:24,代碼來源:v3_watch_test.go


注:本文中的github.com/coreos/etcd/etcdserver/etcdserverpb.Watch_WatchClient.CloseSend方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。