pub struct Sender<T: Send + 'static> { /* private fields */ }
Expand description
Implementations§
source§impl<T: Send + 'static> Sender<T>
impl<T: Send + 'static> Sender<T>
sourcepub fn has_receiver(&self) -> bool
pub fn has_receiver(&self) -> bool
Does anyone can receive a value through this channel.
sourcepub fn send(&self, t: T) -> Result<(), SendError<T>>
pub fn send(&self, t: T) -> Result<(), SendError<T>>
Sends a value on this channel.
This function will block until space in the internal buffer becomes available or a receiver is available to hand off the message to.
Note that a successful send does not guarantee that the receiver will ever see the data if there is a buffer on this channel. Items may be enqueued in the internal buffer for the receiver to receive at a later time. If the buffer size is 0, however, the channel becomes a rendezvous channel and it guarantees that the receiver has indeed received the data if this function returns success.
This function will never panic, but it may return [Err
] if the
Receiver
has disconnected and is no longer able to receive
information.
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 send
for notes about guarantees of whether the
receiver has received the data or not if this function is successful.