Skip to main content

Module par

Module par 

Source
Expand description

Parallel map for loading work that is a pure function of one item (decoding a texture, a sound or a resource): the results come back in input order, so callers see exactly what a sequential map gives. Native builds spread the items over the CPU cores with scoped threads; wasm32 builds run them in order on the calling thread (wasm threads need cross-origin isolation, see docs/PERFORMANCE.md).

Never use this for work that draws from the game’s Random or depends on the order in which items are processed.

Functions§

join
Run background on another thread while foreground runs on this one (native); on wasm32, foreground then background, in order. background must be a pure function of what it reads, so that the order makes no difference.
map
items.iter().map(f).collect(), with the calls to f run on several threads (native).
map_mut
items.iter_mut().map(f).collect() for disjoint parts of one buffer (for example bands of rows of an image). Each thread takes a run of neighbouring items (native).