cloudwego/kitex

关于如何判定ClientSideStreaming的传输结束了

lvxiuquan opened this issue · 1 comments

参考的文档:https://www.cloudwego.io/zh/docs/kitex/tutorials/basic-feature/message_type/

func main() {
    cli, err := echoseervice.NewClient("destServiceName", client.WithHostPorts("0.0.0.0:8888"))
    if err != nil {
        panic(err)
    }
    req := &echo.Request{Msg: "hello"}
    svrStream, err := cli.ServerSideStreaming(context.Background(), req)
    if err != nil {
        panic(err)
    }
    for {
        resp, err := svrStream.Recv()
        log.Println("response:",resp.GetMsg())
        if err != nil {
            panic(err)
        }
        time.Sleep(time.Second)
        // resp.Msg == "world"
    }
}

其中resp, err := svrStream.Recv(),最后err会是io.EOF,如果要判断streaming是非已经结束,标准做法就是判断errors.Is(err, io.EOF)吗?

是的,这里不能直接panic