pub struct Sender<T> { /* private fields */ }
Expand description
Sender that can be dynamically connected to a Receiver
To send data to the connected Receiver
s, use Sender::send
. Call
Sender::reset
to indicate missing data and Sender::finish
to
indicate end of stream.
Connecting the Sender
to a Receiver
is done by passing a
SenderConnector
reference to ReceiverConnector::connect
.
The SenderConnector
is obtained when calling new_sender
.
There is buffer capacity of 1
for each Sender
, i.e. Sender::send
completes immediately for the first value sent or after all Receiver
s
have received the previous value.
(Note: In some cases, Sender::send
may wait until receiving is attempted
by one Receiver
. This is because the broadcast_bp::Sender
might not
see a broadcast_bp::Receiver
as subscriber yet.)
Implementations
sourceimpl<T> Sender<T>
impl<T> Sender<T>
sourcepub async fn reserve(&self) -> Result<Reservation<'_, T>, RsrvError>
pub async fn reserve(&self) -> Result<Reservation<'_, T>, RsrvError>
Wait until ready to send
The returned Reservation
handle may be used to send a value
immediately (through Reservation::send
, which is not async
).
sourcepub fn try_reserve(&self) -> Result<Option<Reservation<'_, T>>, RsrvError>
pub fn try_reserve(&self) -> Result<Option<Reservation<'_, T>>, RsrvError>
Check if ready to send
The returned Reservation
handle may be used to send a value
immediately (through Reservation::send
, which is not async
).
This method returns Ok(None)
if it’s not possible to send a value
immediately.
sourcepub async fn reset(&self) -> Result<(), SendError<()>>
pub async fn reset(&self) -> Result<(), SendError<()>>
Notify all Receiver
s that some data is missing or that the data
stream has been restarted
sourcepub async fn finish(&self) -> Result<(), SendError<()>>
pub async fn finish(&self) -> Result<(), SendError<()>>
Notify all Receiver
s that the data stream has been completed
sourcepub async fn forward_error(&self, error: RecvError) -> Result<(), SendError<()>>
pub async fn forward_error(&self, error: RecvError) -> Result<(), SendError<()>>
Propagate a RecvError
to all Receiver
s
RecvError::Closed
is mapped to RecvError::Reset
because a
Receiver
may be reconnected with another Sender
later.