checkpoint
This commit is contained in:
@@ -60,15 +60,19 @@ func stream() {
|
||||
Count: int64(10),
|
||||
})
|
||||
|
||||
rspChan := make(chan *example.StreamingResponse, 10)
|
||||
|
||||
stream, err := client.Stream(context.Background(), req, rspChan)
|
||||
stream, err := client.Stream(context.Background(), req)
|
||||
if err != nil {
|
||||
fmt.Println("err:", err)
|
||||
return
|
||||
}
|
||||
|
||||
for rsp := range rspChan {
|
||||
for stream.Error() == nil {
|
||||
rsp := &example.StreamingResponse{}
|
||||
err := stream.Recv(rsp)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
break
|
||||
}
|
||||
fmt.Println("Stream: rsp:", rsp.Count)
|
||||
}
|
||||
|
||||
|
@@ -127,30 +127,29 @@ func (c *exampleClient) Call(ctx context.Context, in *Request, opts ...client.Ca
|
||||
|
||||
func (c *exampleClient) Stream(ctx context.Context, in *StreamingRequest, opts ...client.CallOption) (Example_StreamClient, error) {
|
||||
req := c.c.NewRequest(c.serviceName, "Example.Stream", in)
|
||||
outCh := make(chan *StreamingResponse)
|
||||
stream, err := c.c.Stream(ctx, req, outCh, opts...)
|
||||
stream, err := c.c.Stream(ctx, req, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &exampleStreamClient{stream, outCh}, nil
|
||||
return &exampleStreamClient{stream}, nil
|
||||
}
|
||||
|
||||
type Example_StreamClient interface {
|
||||
Next() (*StreamingResponse, error)
|
||||
RecvMsg() (*StreamingResponse, error)
|
||||
client.Streamer
|
||||
}
|
||||
|
||||
type exampleStreamClient struct {
|
||||
client.Streamer
|
||||
next chan *StreamingResponse
|
||||
}
|
||||
|
||||
func (x *exampleStreamClient) Next() (*StreamingResponse, error) {
|
||||
out, ok := <-x.next
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`chan closed`)
|
||||
func (x *exampleStreamClient) RecvMsg() (*StreamingResponse, error) {
|
||||
m := new(StreamingResponse)
|
||||
err := x.Recv(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Server API for Example service
|
||||
|
Reference in New Issue
Block a user