Expand description
Compute function over iterator in a streaming fashion using thread pool and preserving order of elements.
Example
let xs: &[u64] = &[100, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5];
let mut ys = Vec::new();
let f = |x| x*x;
parstream::run(xs, 4,
|x| {
std::thread::sleep(std::time::Duration::from_millis(*x));
f(x)
},
|y| ys.push(y),
);
assert_eq!(ys, xs.iter().map(f).collect::<Vec<_>>());
Warning
First closure in run
should not panic!
Functions
Compute
f(x)
for every x
in xs
using thread pool and call report
for
every result and preserve order of elements.