pub struct RequestSender<Req> { /* private fields */ }Expand description
A handle for sending outbound request items over a streaming RPC.
Typically, you receive a RequestSender as the result of initiating a streaming RPC.
Outbound messages are buffered and sent asynchronously to the server. The buffer size
defaults to 16 and can be configured via
RequestOptionsBuilder::with_request_stream_channel_capacity.
RequestSender is cheaply cloneable. Sending from multiple clones concurrently may
interleave messages; if delivery order is important, send messages sequentially.
The outbound request stream is closed once all clones of the RequestSender are dropped.
§Examples
sender.send("message 1".to_string()).await?;
sender.send("message 2".to_string()).await?;
drop(sender); // Close outbound request streamImplementations§
Source§impl<Req> RequestSender<Req>
impl<Req> RequestSender<Req>
Sourcepub async fn send(&self, item: Req) -> Result<(), SendError>
pub async fn send(&self, item: Req) -> Result<(), SendError>
Sends a request item over the stream.
If the internal request buffer is full, this method awaits asynchronously until
capacity is available. The buffer size defaults to 16 and can be configured via
RequestOptionsBuilder::with_request_stream_channel_capacity.
§Errors
- Returns
SendError::StreamClosedif the stream was closed by the server or receiver. - Returns
SendError::Serializationif the request item cannot be serialized.
§Examples
sender.send("hello".to_string()).await?;Trait Implementations§
Source§impl<Req: Clone> Clone for RequestSender<Req>
impl<Req: Clone> Clone for RequestSender<Req>
Source§impl<Req> Debug for RequestSender<Req>
impl<Req> Debug for RequestSender<Req>
Source§impl<Req> From<Sender<Req>> for RequestSender<Req>where
Req: Send + 'static,
Creates a RequestSender from a Tokio mpsc::Sender, useful for mocking in tests.
impl<Req> From<Sender<Req>> for RequestSender<Req>where
Req: Send + 'static,
Creates a RequestSender from a Tokio mpsc::Sender, useful for mocking in tests.
§Examples
let (tx, mut rx) = mpsc::channel::<String>(16);
let sender = RequestSender::from(tx);