pub struct JobHandle<T> { /* private fields */ }
Expand description
Reference to a Future that has been scheduled via send
Dropping a JobHandle
cancels it, which means its future won’t be polled again.
To drop the JobHandle
handle without canceling it, use detach() instead.
To cancel a task gracefully and wait until it is fully destroyed, use the cancel() method
This type implements Future to allow awaiting on the result of the spawned task
Implementations§
Source§impl<T> JobHandle<T>
impl<T> JobHandle<T>
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 JobHandle
to cancel it, this is a cleaner way of
canceling because it also waits for the task to stop running.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check whether this job has completed
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for JobHandle<T>
impl<T> !RefUnwindSafe for JobHandle<T>
impl<T> !Send for JobHandle<T>
impl<T> !Sync for JobHandle<T>
impl<T> Unpin for JobHandle<T>
impl<T> !UnwindSafe for JobHandle<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
Mutably borrows from an owned value. Read more
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more