pub struct Task<T> { /* private fields */ }Expand description
A spawned task.
Awaiting it gives the task’s output. Dropping it cancels the task: its
future is dropped without being polled again. detach
lets the task run to its end without a handle.
If the task’s future panics, awaiting the handle resumes the panic.
§Panics
Awaiting a task that was cancelled before it completed (through an
AbortHandle, or by its runtime’s shutdown) panics;
join answers a JoinError instead, and
fallible gives a handle that returns None.
Implementations§
Source§impl<T> Task<T>
impl<T> Task<T>
Sourcepub async fn cancel(self) -> Option<T>
pub async fn cancel(self) -> Option<T>
Cancels the task and waits for its future to be dropped. Returns the output if the task had already completed.
Sourcepub fn fallible(self) -> FallibleTask<T> ⓘ
pub fn fallible(self) -> FallibleTask<T> ⓘ
A handle that returns None where this one panics: when the task was
cancelled, or its runtime dropped it before it completed.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether the task completed or was cancelled. Awaiting a finished task returns at once.
Sourcepub fn abort_handle(&self) -> AbortHandle
pub fn abort_handle(&self) -> AbortHandle
A handle that cancels the task from anywhere, without the Task:
it can be cloned and sent to another thread, and outlives the handle.