Skip to main content

JoinSet

Trait JoinSet 

Source
pub trait JoinSet<T>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn spawn<F>(&mut self, task: F) -> Result<(), SpawnError>
       where F: Future<Output = T> + Send + 'static;
    fn join_next<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Option<Result<T, Box<dyn Any + Send>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait representing a collection of tasks spawned on a Runtime.

This is inspired by Tokio’s JoinSet API, which provides a convenient way to spawn tasks and receive their output asynchronously.

Required Methods§

Source

fn spawn<F>(&mut self, task: F) -> Result<(), SpawnError>
where F: Future<Output = T> + Send + 'static,

Spawn the provided task on the runtime.

The provided task will start executing in the background immediately, even if you don’t call JoinSet::join_next.

Source

fn join_next<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Option<Result<T, Box<dyn Any + Send>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Wait until one of the tasks completes, and return its output.

Returns None if there are currently no tasks in this set.

This function is cancel-safe, and therefore safe to use in a select! branch.

§Limitations

If a task panics, this function will yield a Some(Err(..) result. However, this API doesn’t provide a way of telling which task has panicked. Callers wishing to keep track of panics can work around this limitation by wrapping the task’s code in catch_unwind, and arranging for the result returned from this function to contain some additional information identifying the task it originated from (either in a Some(Ok(..)), or in a Some(Er(..)), although the latter would involve downcasting the dyn Any to the concrete error type).

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: Send + 'static> JoinSet<T> for JoinSet<T>

Source§

fn spawn<F>(&mut self, task: F) -> Result<(), SpawnError>
where F: Future<Output = T> + Send + 'static,

Source§

fn join_next<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Option<Result<T, Box<dyn Any + Send>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§

Source§

impl<T, R> JoinSet<T> for FuturesJoinSet<T, R>
where T: Send + Sync + 'static, R: SpawnExt + Send + Sync + 'static,