PendingSender

Struct PendingSender 

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

Source

pub fn into_lowlevel(self) -> PendingSender

Converts the sender into a low-level PendingSender.

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) -> PendingSender<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 sender and polls for progress.

See close for more information.

Source

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

Trait Implementations§

Source§

impl<T> Debug for PendingSender<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 PendingSender<T>

§

impl<T> !RefUnwindSafe for PendingSender<T>

§

impl<T> Send for PendingSender<T>

§

impl<T> Sync for PendingSender<T>

§

impl<T> Unpin for PendingSender<T>

§

impl<T> !UnwindSafe for PendingSender<T>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.