Struct tokio_util::sync::PollSender

source ·
pub struct PollSender<T> { /* private fields */ }
Expand description

A wrapper around mpsc::Sender that can be polled.

Implementations§

source§

impl<T: Send + 'static> PollSender<T>

source

pub fn new(sender: Sender<T>) -> Self

Create a new PollSender.

source

pub fn start_send(&mut self, value: T) -> Result<(), SendError<T>>

Start sending a new item.

This method panics if a send is currently in progress. To ensure that no send is in progress, call poll_send_done first until it returns Poll::Ready.

If this method returns an error, that indicates that the channel is closed. Note that this method is not guaranteed to return an error if the channel is closed, but in that case the error would be reported by the first call to poll_send_done.

source

pub fn poll_send_done( &mut self, cx: &mut Context<'_> ) -> Poll<Result<(), SendError<T>>>

If a send is in progress, poll for its completion. If no send is in progress, this method returns Poll::Ready(Ok(())).

This method can return the following values:

  • Poll::Ready(Ok(())) if the in-progress send has been completed, or there is no send in progress (even if the channel is closed).
  • Poll::Ready(Err(err)) if the in-progress send failed because the channel has been closed.
  • Poll::Pending if a send is in progress, but it could not complete now.

When this method returns Poll::Pending, the current task is scheduled to receive a wakeup when the message is sent, or when the entire channel is closed (but not if just this sender is closed by close_this_sender). Note that on multiple calls to poll_send_done, only the Waker from the Context passed to the most recent call is scheduled to receive a wakeup.

If this method returns Poll::Ready, then start_send is guaranteed to not panic.

source

pub fn is_ready(&self) -> bool

Check whether the channel is ready to send more messages now.

If this method returns true, then start_send is guaranteed to not panic.

If the channel is closed, this method returns true.

source

pub fn is_closed(&self) -> bool

Check whether the channel has been closed.

source

pub fn clone_inner(&self) -> Option<Sender<T>>

Clone the underlying Sender.

If this method returns None, then the channel is closed. (But it is not guaranteed to return None if the channel is closed.)

source

pub fn inner_ref(&self) -> Option<&Sender<T>>

Access the underlying Sender.

If this method returns None, then the channel is closed. (But it is not guaranteed to return None if the channel is closed.)

source

pub fn close_this_sender(&mut self)

Close this sender. No more messages can be sent from this sender.

Note that this only closes the channel from the view-point of this sender. The channel remains open until all senders have gone away, or until the Receiver closes the channel.

If there is a send in progress when this method is called, that send is unaffected by this operation, and poll_send_done can still be called to complete that send.

source

pub fn abort_send(&mut self) -> bool

Abort the current in-progress send, if any.

Returns true if a send was aborted.

Trait Implementations§

source§

impl<T> Clone for PollSender<T>

source§

fn clone(&self) -> PollSender<T>

Clones this PollSender. The resulting clone will not have any in-progress send operations, even if the current PollSender does.

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for PollSender<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: Send + 'static> Sink<T> for PollSender<T>

source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

This is equivalent to calling poll_send_done.

source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

This is equivalent to calling poll_send_done.

source§

fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>

This is equivalent to calling start_send.

source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

This method will first flush the PollSender, and then close it by calling close_this_sender.

If a send fails while flushing because the Receiver has gone away, then this function returns an error. The channel is still successfully closed in this situation.

§

type Error = SendError<T>

The type of value produced by the sink when an error occurs.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for PollSender<T>

§

impl<T> Send for PollSender<T>where T: Send,

§

impl<T> Sync for PollSender<T>where T: Send,

§

impl<T> Unpin for PollSender<T>

§

impl<T> !UnwindSafe for PollSender<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.