maitake::task

Struct TaskRef

Source
pub struct TaskRef(/* private fields */);
Expand description

A type-erased, reference-counted pointer to a spawned Task.

Once a task has been spawned, it is generally referenced by a TaskRef. When a spawned task is placed in a scheduler’s run queue, dequeuing the next task will yield a TaskRef, and a TaskRef may be converted into a Waker or used to await a spawned task’s completion.

TaskRefs are reference-counted, and the task will be deallocated when the last TaskRef pointing to it is dropped.

Implementations§

Source§

impl TaskRef

Source

pub fn id(&self) -> TaskId

Returns a TaskId that uniquely identifies this task.

The returned ID does not increment the task’s reference count, and may persist even after the task it identifies has completed and been deallocated.

Source

pub fn cancel(&self) -> bool

Forcibly cancel the task.

Canceling a task sets a flag indicating that it has been canceled and should terminate. The next time a canceled task is polled by the scheduler, it will terminate instead of polling the inner Future. If the task has a JoinHandle, that JoinHandle will complete with a JoinError. The task then will be deallocated once all JoinHandles and TaskRefs referencing it have been dropped.

This method returns true if the task was canceled successfully, and false if the task could not be canceled (i.e., it has already completed, has already been canceled, cancel culture has gone TOO FAR, et cetera).

Source

pub fn is_complete(&self) -> bool

Returns true if this task has completed.

Tasks are considered completed when the spawned Future has returned Poll::Ready, or if the task has been canceled by the cancel() method.

Note: This method can return false after cancel() has been called. This is because calling cancel begins the process of cancelling a task. The task is not considered canceled until it has been polled by the scheduler after calling cancel().

Trait Implementations§

Source§

impl Clone for TaskRef

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TaskRef

Source§

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

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

impl Drop for TaskRef

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> PartialEq<&JoinHandle<T>> for TaskRef

Source§

fn eq(&self, other: &&JoinHandle<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<&TaskRef> for JoinHandle<T>

Source§

fn eq(&self, other: &&TaskRef) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<JoinHandle<T>> for TaskRef

Source§

fn eq(&self, other: &JoinHandle<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<TaskRef> for JoinHandle<T>

Source§

fn eq(&self, other: &TaskRef) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for TaskRef

Source§

fn eq(&self, other: &TaskRef) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Pointer for TaskRef

Source§

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

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

impl Eq for TaskRef

Source§

impl Send for TaskRef

Source§

impl StructuralPartialEq for TaskRef

Source§

impl Sync for TaskRef

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

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