checkpoint

This commit is contained in:
Asim
2015-12-17 20:37:35 +00:00
parent c73a88e801
commit 6ae48c9f29
11 changed files with 284 additions and 100 deletions

View File

@@ -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)
}

View File

@@ -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