hyperium / tonic

A native gRPC client & server implementation with async/await support.
https://docs.rs/tonic
MIT License
9.32k stars 954 forks source link

how to manually fail a client streaming? #1758

Open glorv opened 1 week ago

glorv commented 1 week ago

Currently, client stream receives a request with type impl tonic::IntoStreamingRequest<Message=...>, it seems not expose a interface to manually fail this streaming. A real world user case is to use client streaming to send a file, each message represent a chunk of this file. It is possible that the source of file may meet error, e.g, read from a disk file meet IO errors, thus we may want to manually terminate the streaming with a fail status so the server side can know that this is not s successful call.

I saw the internal pat of the client streaming will also transfer this stream to Stream<Item=<Result<Message, tonic::Status>>> at:

https://github.com/hyperium/tonic/blob/d312dcc0ec362cb12f6e54072622761d7466a650/tonic/src/codec/encode.rs#L38-L54

thus, it is better to expose the Result to the input type? Why not directly the request type as impl tonic::IntoStreamingRequest<Message=Result<ReqType, tonic::Status>>?