pub struct JoinHandle<T>(/* private fields */);Expand description
An owned permission to join on a task (await its termination).
This can be thought of as the equivalent of std::thread::JoinHandle for a crate::LocalSpawnPool task rather than a thread. You
do not need to .await the JoinHandle to make the task execute — it will start running in the background immediately. When
awaiting the JoinHandle<T>, you will obtain an Option<T>, where T is the output of the spawned future associated with this
handle: it will be None if the task was aborted.
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 join on it.
This struct is created by the crate::LocalSpawnPool::spawn and crate::spawn functions.
§Cancel safety
The JoinHandle<T> type is cancel safe. If it is used as the event in a tokio::select! statement and some other branch
completes first, then it is guaranteed that the output of the task is not lost.
If a JoinHandle is dropped, then the task continues running in the background and its return value is lost.
Implementations§
Source§impl<T> JoinHandle<T>
impl<T> JoinHandle<T>
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true if the task has finished executing. If the task was aborted before finishing execution, it returns false.
Sourcepub fn is_aborted(&self) -> bool
pub fn is_aborted(&self) -> bool
Returns true if the task has been aborted. If JoinHandle::abort was called after the task finished executing, it still
returns false.
Trait Implementations§
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> !Send for JoinHandle<T>
impl<T> !Sync for JoinHandle<T>
impl<T> Unpin for JoinHandle<T>where
T: Unpin,
impl<T> !UnwindSafe for JoinHandle<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<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 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>.