pub struct PendingSender<T> { /* private fields */ }Expand description
A sender 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 sender is claimed,
then this will return a PendingSender.
PendingSenders 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> PendingSender<T>
impl<T> PendingSender<T>
Sourcepub fn into_lowlevel(self) -> PendingSender
pub fn into_lowlevel(self) -> PendingSender
Converts the sender into a low-level PendingSender.
Returns the ChannelCookie, which identifies this channel.
Sourcepub fn cast<U>(self) -> PendingSender<U>
pub fn cast<U>(self) -> PendingSender<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 sender 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 sender.
This will prevent the channel from being established. Any calls to
UnclaimedReceiver::claim will return an error.
let (mut sender, receiver) = handle
.create_channel::<String>()
.claim_sender()
.await?;
// Close the PendingSender:
sender.close().await?;
// Trying to claim the UnclaimedReceiver will fail:
let res = receiver.claim(16).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<Sender<T>, Error>
pub async fn establish(self) -> Result<Sender<T>, Error>
Waits until the channel has been established and returns a Sender.
It can occasionally be useful to only wait until the channel is established, but without
converting self to a Sender. 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_sender()
.await?;
// Claim the receiver:
let mut receiver = receiver.claim(16).await?;
// The channel is now established:
let mut sender = sender.establish().await?;
sender.send_item("Hello :)").await?;
let item = receiver.next_item().await?;
assert_eq!(item.as_deref(), Some("Hello :)"));