Struct async_broadcast::Sender [−][src]
pub struct Sender<T> { /* fields omitted */ }
The sending side of the broadcast channel.
Senders can be cloned and shared among threads. When all senders associated with a channel are dropped, the channel becomes closed.
The channel can also be closed manually by calling Sender::close()
.
Implementations
impl<T: Clone> Sender<T>
[src]
impl<T: Clone> Sender<T>
[src]pub fn broadcast(&self, msg: T) -> Send<'_, T>ⓘ
[src]
pub fn broadcast(&self, msg: T) -> Send<'_, T>ⓘ
[src]Broadcasts a message on the channel.
If the channel is full, this method waits until there is space for a message.
If the channel is closed, this method returns an error.
Examples
use async_broadcast::{broadcast, SendError}; let (s, r) = broadcast(1); assert_eq!(s.broadcast(1).await, Ok(())); drop(r); assert_eq!(s.broadcast(2).await, Err(SendError(2)));
pub fn try_broadcast(&self, msg: T) -> Result<(), TrySendError<T>>
[src]
pub fn try_broadcast(&self, msg: T) -> Result<(), TrySendError<T>>
[src]Attempts to broadcast a message on the channel.
If the channel is full or closed, this method returns an error.
Examples
use async_broadcast::{broadcast, TrySendError}; let (s, r) = broadcast(1); assert_eq!(s.try_broadcast(1), Ok(())); assert_eq!(s.try_broadcast(2), Err(TrySendError::Full(2))); drop(r); assert_eq!(s.try_broadcast(3), Err(TrySendError::Closed(3)));
pub fn close(&self) -> bool
[src]
pub fn close(&self) -> bool
[src]Closes the channel.
Returns true
if this call has closed the channel and it was not closed already.
The remaining messages can still be received.
Examples
use async_broadcast::{broadcast, RecvError}; let (s, mut r) = broadcast(1); s.broadcast(1).await.unwrap(); assert!(s.close()); assert_eq!(r.recv().await.unwrap(), 1); assert_eq!(r.recv().await, Err(RecvError));
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T> where
T: Send,
T: Send,
impl<T> Sync for Sender<T> where
T: Send,
T: Send,
impl<T> Unpin for Sender<T>
impl<T> UnwindSafe for Sender<T>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more