Function git_features::parallel::in_parallel
source · pub fn in_parallel<I, S, O, R>(
input: impl Iterator<Item = I> + Send,
thread_limit: Option<usize>,
new_thread_state: impl Fn(usize) -> S + Send + Clone,
consume: impl Fn(I, &mut S) -> O + Send + Clone,
reducer: R
) -> Result<<R as Reduce>::Output, <R as Reduce>::Error>where
R: Reduce<Input = O>,
I: Send,
O: Send,Available on crate feature
parallel only.Expand description
Read items from input and consume them in multiple threads,
whose output output is collected by a reducer. Its task is to
aggregate these outputs into the final result returned by this function with the benefit of not having to be thread-safe.
- if
thread_limitisSome, the given amount of threads will be used. IfNone, all logical cores will be used. new_thread_state(thread_number) -> Stateproduces thread-local state once per thread to be based toconsumeconsume(Item, &mut State) -> Outputproduces an output given an input obtained byinputalong with mutable state initially created bynew_thread_state(…).- For
reducer, see theReducetrait