Struct Sender
struct Sender<T> { ... }
Sending-half of the broadcast channel.
May be used from many threads. Messages can be sent with
[send][Sender::send].
Examples
use broadcast;
async
Implementations
impl<T> Sender<T>
fn new(capacity: usize) -> SelfCreates the sending-half of the
broadcastchannel.See the documentation of
broadcast::channelfor more information on this method.fn send(self: &Self, value: T) -> Result<usize, SendError<T>>Attempts to send a value to all active
Receiverhandles, returning it back if it could not be sent.A successful send occurs when there is at least one active
Receiverhandle. An unsuccessful send would be one where all associatedReceiverhandles have already been dropped.Return
On success, the number of subscribed
Receiverhandles is returned. This does not mean that this number of receivers will see the message as a receiver may drop or lag (see lagging) before receiving the message.Note
A return value of
Okdoes not mean that the sent value will be observed by all or any of the activeReceiverhandles.Receiverhandles may be dropped before receiving the sent message.A return value of
Errdoes not mean that future calls tosendwill fail. NewReceiverhandles may be created by callingsubscribe.Examples
use broadcast; asyncfn subscribe(self: &Self) -> Receiver<T>Creates a new
Receiverhandle that will receive values sent after this call tosubscribe.Examples
use broadcast; asyncfn downgrade(self: &Self) -> WeakSender<T>Converts the
Senderto aWeakSenderthat does not count towards RAII semantics, i.e. if allSenderinstances of the channel were dropped and onlyWeakSenderinstances remain, the channel is closed.fn len(self: &Self) -> usizeReturns the number of queued values.
A value is queued until it has either been seen by all receivers that were alive at the time it was sent, or has been evicted from the queue by subsequent sends that exceeded the queue's capacity.
Note
In contrast to
Receiver::len, this method only reports queued values and not values that have been evicted from the queue before being seen by all receivers.Examples
use broadcast; asyncfn is_empty(self: &Self) -> boolReturns true if there are no queued values.
Examples
use broadcast; asyncfn receiver_count(self: &Self) -> usizeReturns the number of active receivers.
An active receiver is a
Receiverhandle returned fromchannelorsubscribe. These are the handles that will receive values sent on thisSender.Note
It is not guaranteed that a sent message will reach this number of receivers. Active receivers may never call
recvagain before dropping.Examples
use broadcast; asyncfn same_channel(self: &Self, other: &Self) -> boolReturns
trueif senders belong to the same channel.Examples
use broadcast; asyncasync fn closed(self: &Self)A future which completes when the number of [Receiver]s subscribed to this
Senderreaches zero.Examples
use FutureExt; use broadcast; asyncfn strong_count(self: &Self) -> usizeReturns the number of
Senderhandles.fn weak_count(self: &Self) -> usizeReturns the number of
WeakSenderhandles.
impl<T> Any for Sender<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Sender<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Sender<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Clone for Sender<T>
fn clone(self: &Self) -> Sender<T>
impl<T> CloneToUninit for Sender<T>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> Debug for Sender<T>
fn fmt(self: &Self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result
impl<T> Drop for Sender<T>
fn drop(self: &mut Self)
impl<T> Freeze for Sender<T>
impl<T> From for Sender<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T>
impl<T> Sync for Sender<T>
impl<T> ToOwned for Sender<T>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> Unpin for Sender<T>
impl<T> UnwindSafe for Sender<T>
impl<T, U> Into for Sender<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Sender<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Sender<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>