Struct maitake::task::JoinHandle

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

An owned permission to join a task (await its termination).

This is equivalent to the standard library’s std::thread::JoinHandle type, but for asynchronous tasks rather than OS threads.

A JoinHandle detaches the associated task when it is dropped, which means that there is no longer any handle to the task and no way to await its termination.

JoinHandles implement Future, so a task’s output can be awaited by .awaiting its JoinHandle.

This struct is returned by the Scheduler::spawn and Scheduler::spawn_allocated methods, and the task::Builder::spawn and task::Builder::spawn_allocated methods.

Implementations§

source§

impl<T> JoinHandle<T>

source

pub fn task_ref(&self) -> TaskRef

Returns a TaskRef referencing the task this JoinHandle is associated with.

This increases the task’s reference count; its storage is not deallocated until all such TaskRefs are dropped.

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

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

Trait Implementations§

source§

impl<T> Debug for JoinHandle<T>

source§

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

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

impl<T> Drop for JoinHandle<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T> Future for JoinHandle<T>

§

type Output = Result<T, JoinError<T>>

The type of value produced on completion.
source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
source§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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 TaskId

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> PartialEq<TaskId> for JoinHandle<T>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialEq> PartialEq for JoinHandle<T>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq> Eq for JoinHandle<T>

source§

impl<T> StructuralEq for JoinHandle<T>

source§

impl<T> StructuralPartialEq for JoinHandle<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for JoinHandle<T>

§

impl<T> Send for JoinHandle<T>

§

impl<T> Sync for JoinHandle<T>

§

impl<T> Unpin for JoinHandle<T>

§

impl<T> !UnwindSafe for JoinHandle<T>

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.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T> Instrument for T

§

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

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

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<F> IntoFuture for F
where F: Future,

§

type Output = <F as Future>::Output

The output that the future will produce on completion.
§

type IntoFuture = F

Which kind of future are we turning this into?
source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more