Skip to main content

map_ordered

Function map_ordered 

Source
pub fn map_ordered<T, R>(
    items: &[T],
    f: impl Fn(usize, &T) -> R + Sync,
) -> Vec<R>
where T: Sync, R: Send,
Expand description

Map f over items on up to threads workers, returning results in item order. f receives the item index and the item.

The workers are scoped threads, or the lent Pool’s when one is set, capped at its Pool::workers. A call made from a worker of another stage runs on that worker.

Determinism holds by construction: items are computed independently and results placed by index, so the output is identical at any thread count, pool or not. The caller’s progress watch is re-installed in every worker; f may checkpoint through it. A panic in f resumes on the caller.