Struct aldrin::PendingSender
source · pub struct PendingSender<T: ?Sized> { /* private fields */ }
Expand description
A claimed sender that is waiting for the channel to become established.
PendingSender
s are used to wait until some client has claimed the receiving end of the
channel. This is done with the established
function.
Implementations§
source§impl<T: ?Sized> PendingSender<T>
impl<T: ?Sized> PendingSender<T>
Returns the sender’s ChannelCookie
.
sourcepub fn client(&self) -> Option<&Handle>
pub fn client(&self) -> Option<&Handle>
Returns a handle to the client that was used to create the sender.
None
will be returned if the sender is closed.
sourcepub async fn close(&mut self) -> Result<(), Error>
pub async fn close(&mut self) -> Result<(), Error>
Closes the sender without consuming it.
When closing a PendingSender
, it will no longer be possible to claim the receiver. If it
has already been claimed, then it will receive None
, indicating that the channel has been
closed.
§Examples
§Closing a sender while the receiver hasn’t been claimed yet
use aldrin::Error;
let (mut sender, receiver) = handle.create_channel_with_claimed_sender::<u32>().await?;
// Close the sender.
sender.close().await?;
// For the receiver, an error will be returned when trying to claim it.
let err = receiver.claim(16).await.unwrap_err();
assert_eq!(err, Error::InvalidChannel);
§Closing a sender while the receiver has already been claimed
use aldrin::Error;
let (mut sender, receiver) = handle.create_channel_with_claimed_sender::<u32>().await?;
// Claim the receiver.
let mut receiver = receiver.claim(16).await?;
// Close the sender.
sender.close().await?;
// The receiver will receive None.
assert_eq!(receiver.next_item().await, Ok(None));
sourcepub async fn established(self) -> Result<Sender<T>, Error>
pub async fn established(self) -> Result<Sender<T>, Error>
Waits until the channel has been established.
A channel is established when both ends have been claimed. An error is returned when the receiver has been closed instead of claimed.
sourcepub fn cast<U: ?Sized>(self) -> PendingSender<U>
pub fn cast<U: ?Sized>(self) -> PendingSender<U>
Casts the item type to a different type.