pub struct WaitHandle<'a> { /* private fields */ }
Expand description
Handle for controlling the wait status of a task.
Implementations§
Source§impl WaitHandle<'_>
impl WaitHandle<'_>
Sourcepub fn finish(&mut self) -> bool
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.
Sourcepub fn cancel(&mut self) -> bool
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.
pub fn set_context(&mut self, cx: &Context<'_>)
Sourcepub fn is_pending(&self) -> bool
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
).
Sourcepub fn try_finish(&mut self, cx: &mut Context<'_>) -> bool
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.
Sourcepub fn into_key(self) -> Option<usize>
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
.
Sourcepub fn from_key(waitlist: &Waitlist, key: Option<usize>) -> WaitHandle<'_>
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.