#parallel-iterator #parallel #ordered #iterator #thread

ordered-parallel-iterator

Performs tasks in parallel returning completed tasks in order of appearance

3 unstable releases

0.2.0 May 9, 2024
0.1.1 Apr 18, 2020
0.1.0 Mar 9, 2019

#442 in Concurrency

Download history 1/week @ 2024-07-09 6/week @ 2024-07-16 8/week @ 2024-07-30 7/week @ 2024-08-27 1/week @ 2024-09-10 2/week @ 2024-09-17 29/week @ 2024-09-24 58/week @ 2024-10-01 1/week @ 2024-10-08

73 downloads per month
Used in 2 crates

Unlicense OR MIT

8KB
108 lines

ordered-parallel-iterator

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.

Installation

Add following dependency to your Cargo.toml:

[dependencies]
ordered-parallel-iterator = "0.2"

Usage

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.


lib.rs:

Crate ordered-parallel-iterator 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).

Installation

Add following dependency to your Cargo.toml:

[dependencies]
ordered-parallel-iterator = "0.2"

Usage

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.

Dependencies

~215KB