Skip to main content

process_stream_concurrently

Function process_stream_concurrently 

Source
pub async fn process_stream_concurrently<T, F>(
    stream: impl Stream<Item = T>,
    process_fn: F,
    process_fn_hack: impl for<'a> Fn(&'a F, T) -> BoxFuture<'a, Result<(), Error>>,
) -> Result<(), Error>
where F: AsyncFn(T) -> Result<(), Error>,
Expand description

Process items from a stream concurrently.

For each item received from stream, calls process_fn to create a future, then runs all futures concurrently. If any future returns an error, stops processing and returns that error.

This is useful for patterns where you receive work items from a channel and want to process them concurrently while respecting backpressure.