Skip to main content

par_try_map

Function par_try_map 

Source
pub fn par_try_map<T, R, E, F>(
    enabled: bool,
    items: Vec<T>,
    f: F,
) -> Result<Vec<R>, E>
where T: Send, R: Send, E: Send, F: Fn(T) -> Result<R, E> + Sync,
Expand description

Maps f over items and returns the results in item order, or the first error in item order.

When enabled, idle rayon workers help the calling thread: it claims items from a shared counter and runs them itself, and spawns helpers that claim items the same way. A helper that starts late finds nothing left and returns. Unlike a rayon join or parallel iterator, the caller waits for helpers that are still running an item by yielding, not inside rayon, so it does not pick up an unrelated queued job and run it before its own continuation. Only the scope’s end waits inside rayon, and only for helpers that have no item left.

A serial map stops at the first error; a parallel one stops claiming items after one.