pub enum Sender<T> {
Tokio(Sender<T>),
Boxed(Arc<dyn DynSender<T>>),
}Expand description
Single producer, single consumer sender.
For the local case, this wraps a tokio::sync::mpsc::Sender.
Variants§
Implementations§
Source§impl<T: Send + Sync + 'static> Sender<T>
impl<T: Send + Sync + 'static> Sender<T>
Sourcepub fn with_filter<F>(self, f: F) -> Sender<T>
pub fn with_filter<F>(self, f: F) -> Sender<T>
Applies a filter before sending.
Messages that don’t pass the filter are dropped.
If you want to combine multiple filters and maps with minimal
overhead, use with_filter_map directly.
Sourcepub fn with_map<U, F>(self, f: F) -> Sender<U>
pub fn with_map<U, F>(self, f: F) -> Sender<U>
Applies a transform before sending.
If you want to combine multiple filters and maps with minimal
overhead, use with_filter_map directly.
Sourcepub fn with_filter_map<U, F>(self, f: F) -> Sender<U>
pub fn with_filter_map<U, F>(self, f: F) -> Sender<U>
Applies a filter and transform before sending.
Any combination of filters and maps can be expressed using a single filter_map.
Source§impl<T: Send + 'static> Sender<T>
impl<T: Send + 'static> Sender<T>
Sourcepub async fn send(&self, value: T) -> Result<(), SendError>
pub async fn send(&self, value: T) -> Result<(), SendError>
Send a message and yield until either it is sent or an error occurs.
§Cancellation safety
If the future is dropped before completion, and if this is a remote sender,
then the sender will be closed and further sends will return an SendError::Io
with std::io::ErrorKind::BrokenPipe. Therefore, make sure to always poll the
future until completion if you want to reuse the sender or any clone afterwards.
Sourcepub async fn try_send(&self, value: T) -> Result<bool, SendError>
pub async fn try_send(&self, value: T) -> Result<bool, SendError>
Try to send a message, returning as fast as possible if sending is not currently possible. This can be used to send ephemeral messages.
For the local case, this will immediately return false if the channel is full.
For the remote case, it will attempt to send the message and return false if sending the first byte fails, otherwise yield until the message is completely sent or an error occurs. This guarantees that the message is sent either completely or not at all.
Returns true if the message was sent.
§Cancellation safety
If the future is dropped before completion, and if this is a remote sender,
then the sender will be closed and further sends will return an SendError::Io
with std::io::ErrorKind::BrokenPipe. Therefore, make sure to always poll the
future until completion if you want to reuse the sender or any clone afterwards.
Trait Implementations§
Source§impl<T: RpcMessage> From<SendStream> for Sender<T>
Available on crate feature rpc only.
impl<T: RpcMessage> From<SendStream> for Sender<T>
rpc only.