par-stream icon indicating copy to clipboard operation
par-stream copied to clipboard

Unexpected behavior when using tokio runtime

Open saintazunya opened this issue 3 years ago • 2 comments

Hi,

Thanks for creating this amazing project. It saved me a lot of boiler plates to run async tasks in parallel. During my useage of this lib, I found that when using tokio as runtime, but not enabling the feature runtime-tokio will produce unexpected behaviors in programs.

Observed behavior:

use futures::prelude::*;
use par_stream::prelude::*;

let doubled: Vec<_> = stream::iter(0..1000)
    // doubles the values in parallel
    .par_then(None, move |value| async move { value * 2 })
    // the collected values will be ordered
    .collect()
    .await;
let expect: Vec<_> = (0..1000).map(|value| value * 2).collect();
assert_eq!(doubled, expect);

assert failed because the variable doubled is an empty Vector.

Expected behavior:

panic during compilation.

Thanks for supporting!

saintazunya avatar Aug 15 '22 04:08 saintazunya

I've noticed I've run into this kind of issue when I forget to add the tokio runtime feature in Cargo.toml, like so: par-stream = { version = "0.10.2", features = ["runtime-tokio"] } Without a runtime, it just passes through, doing nothing. I'm not sure if this is desirable, tbh, but now I know :)

cryptoquick avatar May 04 '23 12:05 cryptoquick

Stumbled upon this as well. Seems like the stream is immediately closed, which is totally unexpected.

axos88 avatar Oct 31 '23 16:10 axos88