pub struct JoinHandle<T> { /* private fields */ }Expand description
An owned permission to join on a task (await its termination).
This can be seen as an equivalent to std::thread::JoinHandle but for Future tasks rather than a thread.
Note that the task associated with this JoinHandle will start running when
Executor::spawn is called according to the selected runtime, even if the
JoinHandle has not been awaited.
Dropping JoinHandle will not abort or cancel the task. In other words, the task will continue to run in the background
and any return value will be lost.
This struct is created by the Executor::spawn.
Implementations§
Source§impl<T> JoinHandle<T>
impl<T> JoinHandle<T>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Provide an empty JoinHandle with no associated task.
Source§impl<T> JoinHandle<T>
impl<T> JoinHandle<T>
Sourcepub fn abort(&self)
pub fn abort(&self)
Abort the task associated with the handle.
If cancellation is observed after this method is called, awaiting the
handle returns JoinError::Aborted. Cancellation without an abort
request through this handle returns JoinError::Cancelled.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Check if the task associated with this JoinHandle has finished.
Note that this method can return false even if JoinHandle::abort has been called on the
task due to the time it may take for the task to cancel.
Sourcepub fn replace(&mut self, handle: JoinHandle<T>)
pub fn replace(&mut self, handle: JoinHandle<T>)
Replace the current handle with the provided JoinHandle, while dropping the source.
§Warning
Note that if this is called with a non-empty handle, the existing task
will not be terminated when it is replaced and could run indefinitely.
Best to use when JoinHandle is JoinHandle::empty where empty is a used
placeholder.
Sourcepub fn replace_in_place(&mut self, handle: &mut JoinHandle<T>)
pub fn replace_in_place(&mut self, handle: &mut JoinHandle<T>)
Replace the current handle with the provided JoinHandle, making the source become
an equivalent to JoinHandle::empty.
§Warning
Note that if this is called with a non-empty handle, the existing task
will not be terminated when it is replaced and could run indefinitely.
Best to use when JoinHandle is JoinHandle::empty where empty is a used
placeholder, and you want to update the source later with another task handle.
Trait Implementations§
Source§impl<T> Debug for JoinHandle<T>
impl<T> Debug for JoinHandle<T>
Source§impl<T> From<JoinHandle<T>> for AbortableJoinHandle<T>
impl<T> From<JoinHandle<T>> for AbortableJoinHandle<T>
Source§fn from(handle: JoinHandle<T>) -> Self
fn from(handle: JoinHandle<T>) -> Self
Source§impl<T> Future for JoinHandle<T>
impl<T> Future for JoinHandle<T>
Auto Trait Implementations§
impl<T> !Freeze for JoinHandle<T>
impl<T> !RefUnwindSafe for JoinHandle<T>
impl<T> !UnwindSafe for JoinHandle<T>
impl<T> Send for JoinHandle<T>where
InnerJoinHandle<T>: Send,
impl<T> Sync for JoinHandle<T>where
InnerJoinHandle<T>: Sync,
impl<T> Unpin for JoinHandle<T>where
InnerJoinHandle<T>: Unpin,
impl<T> UnsafeUnpin for JoinHandle<T>where
InnerJoinHandle<T>: UnsafeUnpin,
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<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F> ⓘ
fn map<U, F>(self, f: F) -> Map<Self, F> ⓘ
Source§fn map_into<U>(self) -> MapInto<Self, U> ⓘ
fn map_into<U>(self) -> MapInto<Self, U> ⓘ
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> ⓘ
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> ⓘ
f. Read moreSource§fn left_future<B>(self) -> Either<Self, B> ⓘ
fn left_future<B>(self) -> Either<Self, B> ⓘ
Source§fn right_future<A>(self) -> Either<A, Self> ⓘ
fn right_future<A>(self) -> Either<A, Self> ⓘ
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self> ⓘ
fn flatten(self) -> Flatten<Self> ⓘ
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self> ⓘwhere
Self: Sized,
fn fuse(self) -> Fuse<Self> ⓘwhere
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ
fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ
Source§fn catch_unwind(self) -> CatchUnwind<Self> ⓘwhere
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self> ⓘwhere
Self: Sized + UnwindSafe,
Source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
() on completion and sends
its output to another future on a separate task. Read moreSource§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self> ⓘwhere
Self: Sized,
fn unit_error(self) -> UnitError<Self> ⓘwhere
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.Source§fn never_error(self) -> NeverError<Self> ⓘwhere
Self: Sized,
fn never_error(self) -> NeverError<Self> ⓘwhere
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.