Struct PendingReceiver

Source
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>

Source

pub fn into_lowlevel(self) -> PendingReceiver

Converts the receiver into a low-level PendingReceiver.

Source

pub fn client(&self) -> &Handle

Returns a Handle to the associated client.

Source

pub fn cookie(&self) -> ChannelCookie

Returns the ChannelCookie, which identifies this channel.

Source

pub fn cast<U>(self) -> PendingReceiver<U>

Casts the item type to a different type U.

Source

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.

Source

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);
Source

pub fn poll_wait_established(&mut self, cx: &mut Context<'_>) -> Poll<()>

Polls the channel for whether it has been established.

When this method returns Poll::Ready(()), then establish will resolve immediately.

Note that this method does not indicate errors. You must use establish to check whether the channel was successfully established.

Source

pub async fn wait_established(&mut self)

Waits until the channel has been established.

When this method returns, then establish will resolve immediately.

Note that this method does not indicate errors. You must use establish to check whether the channel was successfully established.

Source

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 :)"));

Trait Implementations§

Source§

impl<T> Debug for PendingReceiver<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for PendingReceiver<T>

§

impl<T> !RefUnwindSafe for PendingReceiver<T>

§

impl<T> Send for PendingReceiver<T>

§

impl<T> Sync for PendingReceiver<T>

§

impl<T> Unpin for PendingReceiver<T>

§

impl<T> !UnwindSafe for PendingReceiver<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.