Struct WaitHandle

Source
pub struct WaitHandle<'a> { /* private fields */ }
Expand description

Handle for controlling the wait status of a task.

Implementations§

Source§

impl WaitHandle<'_>

Source

pub fn finish(&mut self) -> bool

Mark this task as completed.

If this handle still has a waker on the queue, remove that waker without triggering another notify and return true. Otherwise, return false.

Source

pub fn cancel(&mut self) -> bool

Mark that the task was cancelled.

If this handle currently has a waker on the queue and there is at least one other task waiting on the queue, remove this waker from the queue, wake the next task, and return true. Otherwise return false.

Source

pub fn set_context(&mut self, cx: &Context<'_>)

Source

pub fn is_pending(&self) -> bool

Return true if the WaitHandle has been polled at least once, and has not been completed (by calling either finish or cancel).

Source

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

Mark as finished if this was notified, otherwise update the context.

This is roughly equivalent to

let did_finish = if handle.finish() {
  handle.set_context(&cx);
  false
} else {
  true
};

but operates atomically on the waitlist.

Source

pub fn into_key(self) -> Option<usize>

Convert into a key that can later be used with from_key to convert back into a WaitHandle.

Source

pub fn from_key(waitlist: &Waitlist, key: Option<usize>) -> WaitHandle<'_>

Create a WaitHandle for a Waitlist using a key that was previously acquired from into_key.

For this to work as expected, key should be a key returned by a previous call to into_key on a WaitHandle that was created from the same waitlist. This takes ownership of the wait entry for this key.

You should avoid using this if possible, but in some cases it is necessary to avoid self-reference.

Trait Implementations§

Source§

impl<'a> Drop for WaitHandle<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for WaitHandle<'a>

§

impl<'a> RefUnwindSafe for WaitHandle<'a>

§

impl<'a> Send for WaitHandle<'a>

§

impl<'a> Sync for WaitHandle<'a>

§

impl<'a> Unpin for WaitHandle<'a>

§

impl<'a> UnwindSafe for WaitHandle<'a>

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.