pub struct PendingReceiver<T> { /* private fields */ }Expand description
A receiver that is waiting for the channel to be established.
When creating channels, one of the channel ends is always claimed by the local client, depending
on whether ChannelBuilder::claim_sender or
claim_receiver is used. If the receiver is claimed,
then this will return a PendingReceiver.
PendingReceivers are an intermediate step before the channel is fully
established. It’s purpose is to wait until the other channel end is claimed as well.
Implementations§
Source§impl<T> PendingReceiver<T>
impl<T> PendingReceiver<T>
Sourcepub fn into_lowlevel(self) -> PendingReceiver
pub fn into_lowlevel(self) -> PendingReceiver
Converts the receiver into a low-level PendingReceiver.
Returns the ChannelCookie, which identifies this channel.
Sourcepub fn cast<U>(self) -> PendingReceiver<U>
pub fn cast<U>(self) -> PendingReceiver<U>
Casts the item type to a different type U.
Sourcepub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
pub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
Initiates closing the receiver and polls for progress.
See close for more information.
Sourcepub async fn close(&mut self) -> Result<(), Error>
pub async fn close(&mut self) -> Result<(), Error>
Closes the receiver.
This will prevent the channel from being established. Any calls to
UnclaimedSender::claim will return an error.
let (sender, mut receiver) = handle
.create_channel::<String>()
.claim_receiver(16)
.await?;
// Close the PendingReceiver:
receiver.close().await?;
// Trying to claim the UnclaimedSender will fail:
let res = sender.claim().await;
assert_eq!(res.unwrap_err(), Error::InvalidChannel);Sourcepub fn poll_wait_established(&mut self, cx: &mut Context<'_>) -> Poll<()>
pub fn poll_wait_established(&mut self, cx: &mut Context<'_>) -> Poll<()>
Sourcepub async fn wait_established(&mut self)
pub async fn wait_established(&mut self)
Sourcepub async fn establish(self) -> Result<Receiver<T>, Error>
pub async fn establish(self) -> Result<Receiver<T>, Error>
Waits until the channel has been established and returns a Receiver.
It can occasionally be useful to only wait until the channel is established, but without
converting self to a Receiver. This can e.g. happen in select! macros or similar
situations. The reason is, that this method takes self by value and is not
cancel-safe. Use wait_established in such cases.
let (sender, receiver) = handle
.create_channel::<String>()
.claim_receiver(16)
.await?;
// Claim the sender:
let mut sender = sender.claim().await?;
// The channel is now established:
let mut receiver = receiver.establish().await?;
sender.send_item("Hello :)").await?;
let item = receiver.next_item().await?;
assert_eq!(item.as_deref(), Some("Hello :)"));