sui_indexer_alt_framework::task

Trait TrySpawnStreamExt

Source
pub trait TrySpawnStreamExt: Stream {
    // Required method
    fn try_for_each_spawned<Fut, F, E>(
        self,
        limit: impl Into<Option<usize>>,
        f: F,
    ) -> impl Future<Output = Result<(), E>>
       where Fut: Future<Output = Result<(), E>> + Send + 'static,
             F: FnMut(Self::Item) -> Fut,
             E: Send + 'static;
}
Expand description

Extension trait introducing try_for_each_spawned to all streams.

Required Methods§

Source

fn try_for_each_spawned<Fut, F, E>( self, limit: impl Into<Option<usize>>, f: F, ) -> impl Future<Output = Result<(), E>>
where Fut: Future<Output = Result<(), E>> + Send + 'static, F: FnMut(Self::Item) -> Fut, E: Send + 'static,

Attempts to run this stream to completion, executing the provided asynchronous closure on each element from the stream as elements become available.

This is similar to [StreamExt::for_each_concurrent], but it may take advantage of any parallelism available in the underlying runtime, because each unit of work is spawned as its own tokio task.

The first argument is an optional limit on the number of tasks to spawn concurrently. Values of 0 and None are interpreted as no limit, and any other value will result in no more than that many tasks being spawned at one time.

§Safety

This function will panic if any of its futures panics, will return early with success if the runtime it is running on is cancelled, and will return early with an error propagated from any worker that produces an error.

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.

Implementors§

Source§

impl<S: Stream + Sized + 'static> TrySpawnStreamExt for S