Struct aldrin::PendingReceiver
source · pub struct PendingReceiver<T: Deserialize> { /* private fields */ }
Expand description
A claimed receiver that is waiting for the channel to become established.
PendingReceiver
s are used to wait until some client has claimed the sending end of the
channel. This is done with the established
function.
Implementations§
source§impl<T: Deserialize> PendingReceiver<T>
impl<T: Deserialize> PendingReceiver<T>
sourcepub fn client(&self) -> Option<&Handle>
pub fn client(&self) -> Option<&Handle>
Returns a handle to the client that was used to create the receiver.
None
will be returned if the receiver is closed.
sourcepub async fn close(&mut self) -> Result<(), Error>
pub async fn close(&mut self) -> Result<(), Error>
Closes the receiver without consuming it.
When closing a PendingReceiver
, it will no longer be possible to claim the sender.
When the sender has already been claimed, the situation is a little bit more complicated. The sender is notified asynchronously about the receiver’s closing. It will, sooner or later, receive an error when sending an item.
§Examples
§Closing a receiver while the sender hasn’t been claimed yet
use aldrin::Error;
let (sender, mut receiver) = handle.create_channel_with_claimed_receiver::<u32>(16).await?;
// Close the receiver.
receiver.close().await?;
// For the sender, an error will be returned when trying to claim it.
let err = sender.claim().await.unwrap_err();
assert_eq!(err, Error::InvalidChannel);
sourcepub async fn established(self) -> Result<Receiver<T>, Error>
pub async fn established(self) -> Result<Receiver<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 sender has been closed instead of claimed.
sourcepub fn cast<U: Deserialize>(self) -> PendingReceiver<U>
pub fn cast<U: Deserialize>(self) -> PendingReceiver<U>
Casts the item type to a different type.