Struct aldrin::PendingSender
source · pub struct PendingSender<T: Serialize + ?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: Serialize + ?Sized> PendingSender<T>
impl<T: Serialize + ?Sized> PendingSender<T>
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: Serialize + ?Sized>(self) -> PendingSender<U>
pub fn cast<U: Serialize + ?Sized>(self) -> PendingSender<U>
Casts the item type to a different type.
Trait Implementations§
Auto Trait Implementations§
impl<T: ?Sized> Freeze for PendingSender<T>
impl<T> !RefUnwindSafe for PendingSender<T>
impl<T: ?Sized> Send for PendingSender<T>
impl<T: ?Sized> Sync for PendingSender<T>
impl<T: ?Sized> Unpin for PendingSender<T>
impl<T> !UnwindSafe for PendingSender<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more