pub trait AsyncJoinHandle<T: Send + 'static>: Send + 'static {
// Required methods
fn join(self) -> impl Future<Output = Result<T, ()>> + Send;
fn detach(self);
}Expand description
A handle for managing spawned async tasks.
This trait provides methods for waiting for a task’s completion or detaching it to run in the background.
§Type Parameters
T- The return type of the task
Required Methods§
Sourcefn join(self) -> impl Future<Output = Result<T, ()>> + Send
fn join(self) -> impl Future<Output = Result<T, ()>> + Send
Wait for the task to complete and return its result.
This method returns a future that resolves to either the task’s successful result or an error if the task panicked.
§Returns
A future that resolves to Ok(T) if the task completed successfully,
or Err(()) if the task failed.
Sourcefn detach(self)
fn detach(self)
Detach the task to run in the background without waiting for its result.
After calling this method, the task will continue running until it completes or the program exits, but there will be no way to retrieve its result.
§Warning
Some runtimes (like smol) will cancel the future if you drop the task handle
without calling this method. If you want the task to continue running in
the background, you must explicitly call detach() rather than just
dropping the handle.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.