Crates.io | ordered-parallel-iterator |
lib.rs | ordered-parallel-iterator |
version | 0.2.0 |
source | src |
created_at | 2019-03-09 09:40:30.72412 |
updated_at | 2024-05-09 18:38:24.188807 |
description | Performs tasks in parallel returning completed tasks in order of appearance. |
homepage | https://github.com/kilork/ordered-parallel-iterator |
repository | https://github.com/kilork/ordered-parallel-iterator |
max_upload_size | |
id | 119600 |
size | 12,517 |
This crate provides an iterator over task results which performs tasks in parallel returning completed tasks in order of source range iterator. It can be useful if you need to process some data in parallel but need to have results in the order of appearance (FIFO).
Dual-licensed under MIT or the UNLICENSE.
Add following dependency to your Cargo.toml
:
[dependencies]
ordered-parallel-iterator = "0.2"
use ordered_parallel_iterator::OrderedParallelIterator;
fn run_me(x: usize) -> usize {
x + 1
}
fn main() {
for i in OrderedParallelIterator::new(|| 0..10, || run_me) {
println!("Result from iterator: {}", i);
}
}
In this example each run_me
call will happen in own thread, but results will be returned sequentially as fast as first will be finished. Count of pending tasks running in parallel bind to count of CPU cores.