pub struct Task<T>(/* private fields */);
Expand description
Wraps async_executor::Task
, a spawned future.
Tasks are also futures themselves and yield the output of the spawned future.
When a task is dropped, its gets canceled and won’t be polled again. To cancel a task a bit
more gracefully and wait until it stops running, use the Task::cancel()
method.
Tasks that panic get immediately canceled. Awaiting a canceled task also causes a panic.
Implementations§
Source§impl<T> Task<T>
impl<T> Task<T>
Sourcepub fn detach(self)
pub fn detach(self)
Detaches the task to let it keep running in the background. See
async_executor::Task::detach
Sourcepub async fn cancel(self) -> Option<T>
pub async fn cancel(self) -> Option<T>
Cancels the task and waits for it to stop running.
Returns the task’s output if it was completed just before it got canceled, or None
if
it didn’t complete.
While it’s possible to simply drop the Task
to cancel it, this is a cleaner way of
canceling because it also waits for the task to stop running.
See async_executor::Task::cancel
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true
if the current task is finished.
Unlike poll, it doesn’t resolve the final value, it just checks if the task has finished. Note that in a multithreaded environment, this task can be finished immediately after calling this function.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Task<T>
impl<T> RefUnwindSafe for Task<T>
impl<T> Send for Task<T>where
T: Send,
impl<T> Sync for Task<T>
impl<T> Unpin for Task<T>
impl<T> UnwindSafe for Task<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<F> FutureExt for F
impl<F> FutureExt for F
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
std
only.