Expand description
Defines types and handles for streaming RPCs.
In streaming RPCs, the client and server can stream messages to each other
asynchronously. This module provides RequestSender to send outbound request
messages and ResponseStream to receive inbound response messages.
Client libraries use these types to manage streaming communication without exposing raw gRPC transport or Protobuf wire models in the public API.
Connection establishment begins immediately when the streaming RPC is initiated.
In bidirectional streaming, the server may require initial request messages sent via
RequestSender before returning response headers; completing this handshake is awaited
on the first call to ResponseStream::next().
§Examples
Sending requests and receiving responses in a bidirectional streaming RPC:
async fn interact_with_bidi_stream(
sender: RequestSender<String>,
mut stream: ResponseStream<String>,
) -> anyhow::Result<()> {
// Send request messages to the server:
sender.send("hello".to_string()).await?;
// Close the outbound request stream when done sending:
drop(sender);
// Receive response messages from the server:
while let Some(response) = stream.next().await {
let response = response?;
println!("Received response: {response:?}");
}
Ok(())
}Receiving response messages in a server-streaming RPC:
async fn interact_with_server_stream(mut stream: ResponseStream<String>) -> Result<()> {
// Receive response messages from the server:
while let Some(response) = stream.next().await {
let response = response?;
println!("Received response: {response:?}");
}
Ok(())
}Structs§
- Request
Sender - A handle for sending outbound request items over a streaming RPC.
- Response
Stream - A handle for receiving inbound response items from a streaming RPC.
Enums§
- Send
Error - An error returned when sending a request over a stream fails.