pub struct Sender<T> { /* private fields */ }
Expand description
The sending-half of the channel.
Each instance of Sender
can only be used in a single thread, but it can be
cloned to create new Sender
instances for the same underlying channel and
these new instances can be sent to other threads.
Implementations§
Source§impl<T> Sender<T>
impl<T> Sender<T>
Sourcepub fn send(&self, t: T) -> Result<(), SendError<T>>
pub fn send(&self, t: T) -> Result<(), SendError<T>>
Attempts to send a value on this channel, returning it back if it could not be sent.
A successful send occurs when it is determined that the other end of the channel has not hung up already. An unsuccessful send would be one where the corresponding receiver has already been deallocated. Note that a return value of Err means that the data will never be received, but a return value of Ok does not mean that the data will be received. It is possible for the corresponding receiver to hang up immediately after this function returns Ok.
This function will block the current thread until the channel has capacity to accept the value or there are no more receivers to accept the value.
Sourcepub fn send_timeout(
&self,
t: T,
timeout: Duration,
) -> Result<(), SendTimeoutError<T>>
pub fn send_timeout( &self, t: T, timeout: Duration, ) -> Result<(), SendTimeoutError<T>>
Attempts to send a value on this channel, blocking for at most
timeout
.
The function will always block the current thread if the channel has no
available capacity for handling the message. The thread will be blocked
for at most timeout
, after which, if there still is no capacity,
SendTimeoutError::Timeout
will be returned.
Sourcepub fn try_send(&self, t: T) -> Result<(), TrySendError<T>>
pub fn try_send(&self, t: T) -> Result<(), TrySendError<T>>
Attempts to send a value on this channel without blocking.
This method differs from send
by returning immediately if the channel’s
buffer is full or no receiver is waiting to acquire some data. Compared
with send
, this function has two failure cases instead of one (one for
disconnection, one for a full buffer).
See Sender::send
for notes about guarantees of whether the receiver
has received the data or not if this function is successful.