pub struct JoinHandle<T> { /* private fields */ }
Expand description
An owned permission to join on a task (awaiting its termination).
This can be thought of as the equivalent of
std::thread::JoinHandle
or tokio::task::JoinHandle
for
a task that is executed concurrently.
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::spawn and crate::spawn_blocking functions.
§Examples
Creation from crate::spawn
:
let join_handle: async_wasm_task::JoinHandle<_> = async_wasm_task::spawn(async {
// some work here
});
Creation from crate::spawn_blocking
:
let join_handle: async_wasm_task::JoinHandle<_> = async_wasm_task::spawn_blocking(|| {
// some blocking work here
});
Child being detached and outliving its parent:
let original_task = async_wasm_task::spawn(async {
let _detached_task = async_wasm_task::spawn(async {
// Here we sleep to make sure that the first task returns before.
// Assume that code takes a few seconds to execute here.
// This will be called, even though the JoinHandle is dropped.
println!("♫ Still alive ♫");
});
});
original_task.await.expect("The task being joined has panicked");
println!("Original task is joined.");
Trait Implementations§
Source§impl<T> Debug for JoinHandle<T>where
T: Debug,
impl<T> Debug for JoinHandle<T>where
T: Debug,
Source§impl<T> Future for JoinHandle<T>
impl<T> Future for JoinHandle<T>
impl<T: Send> Send for JoinHandle<T>
impl<T: Send> Sync for JoinHandle<T>
impl<T> Unpin for JoinHandle<T>
Auto Trait Implementations§
impl<T> Freeze for JoinHandle<T>
impl<T> !RefUnwindSafe for JoinHandle<T>
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
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