【发布时间】:2018-03-20 19:59:19
【问题描述】:
有人可以帮助我了解 gRPC 代码客户端中通道的用法(用于双向流 RPC): https://grpc.io/docs/tutorials/basic/go.html
这是代码:
stream, err := client.RouteChat(context.Background())
waitc := make(chan struct{})
go func() {
for {
in, err := stream.Recv()
if err == io.EOF {
// read done.
close(waitc)
return
}
if err != nil {
log.Fatalf("Failed to receive a note : %v", err)
}
log.Printf("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude)
}
}()
for _, note := range notes {
if err := stream.Send(note); err != nil {
log.Fatalf("Failed to send a note: %v", err)
}
}
stream.CloseSend()
<-waitc
谢谢!
【问题讨论】:
-
具体有什么需要帮助理解的?