par-stream: Asynchronous Parallel Stream for Rust

An Rust implementation of asynchronous parallel streams analogous to rayon.

It is a re-design of async-rs/parallel-stream. It guarantees the compatibility with futures stream by providing extension traits. Unlike parallel-stream, it does not introduce incompatible types.

Usage

The crate is not published to crates.io yet. Add the Git repository to your Cargo.toml to include this crate.

toml [dependencies] par-stream = "0.2"

Features

Easy usage

Add one line and you can obtain parallel combinators on existing futures stream.

rust use par_stream::ParStreamExt;

Parallel combinators

The limit parameter configures the worker pool size. It accepts the following values:

Scatter and gather combinators

The feature is convenient to work with your custom organization of parallel workers.

stream.par_scatter(buf_size) allows you to convert a stream to a scattering worker and a clonable receiver. You can distribute cloned receivers to respective workers to share a stream.

par_gather(streams, buf_size) gathers multiple streams into one stream.

```rust let (scatterfut, rx) = stream.parscatter(buf_size);

let rx1 = rx.clone(); let rx2 = rx.clone();

let stream1 = worker1(rx1); let stream2 = worker1(rx2);

let gatheredstream = parstream::pargather(vec![stream1, stream2], bufsize); ```

Control the ordering of stream items

The combination of stream.overflowing_enumerate() and stream.reorder_enumerated() enable you to control the ordering of the stream items.

It gives the way to mark items with index numbers, apply to multiple unordered parallel tasks, and reorder them back. It effectively avoids reordering after each parallel task.

rust stream // mark items with index numbers .overflowing_enumerate() // a series of unordered maps .par_then_unordered(limit, map_fut1) .par_then_unordered(limit, map_fut2) .par_then_unordered(limit, map_fut3) // reorder the items back by indexes .reorder_enumerated()

Example

Please visit the example directory to see usages of the crate.

License

MIT License. See LICENSE file.