Skip to main content

JoinSetExt

Trait JoinSetExt 

Source
pub trait JoinSetExt: Sized + Send {
    // Required methods
    fn spawn_task<F: Future<Output: Send> + Send + 'static>(
        &mut self,
        future: F,
    ) -> TaskHandle<F::Output> ;
    fn await_all_tasks(&mut self) -> impl Future<Output = ()> + Send;
    fn await_all_tasks_logging_panics(
        &mut self,
    ) -> impl Future<Output = ()> + Send;
    fn reap_finished_tasks(&mut self);
}
Expand description

An extension trait for the JoinSet type.

Required Methods§

Source

fn spawn_task<F: Future<Output: Send> + Send + 'static>( &mut self, future: F, ) -> TaskHandle<F::Output>

Spawns a future task on this JoinSet using JoinSet::spawn.

Returns a oneshot::Receiver to receive the future’s output, and an AbortHandle to cancel execution of the task.

Source

fn await_all_tasks(&mut self) -> impl Future<Output = ()> + Send

Awaits all tasks spawned in this JoinSet, re-raising the panic of any task that panicked.

Tokio catches a task’s panic instead of stopping the runtime, so a set of long-lived tasks that is merely drained leaves the process running with one of its subsystems silently gone. Re-raising turns that into an exit, which a supervisor can act on.

For sets of tasks that each serve a single request or connection, where losing one is recoverable and exiting would let one caller stop the process, use JoinSetExt::await_all_tasks_logging_panics instead.

Source

fn await_all_tasks_logging_panics(&mut self) -> impl Future<Output = ()> + Send

Awaits all tasks spawned in this JoinSet, logging rather than re-raising the panic of any task that panicked.

Source

fn reap_finished_tasks(&mut self)

Reaps tasks that have finished.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§