par-stream
par-stream copied to clipboard
Unexpected behavior when using tokio runtime
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!
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 :)
Stumbled upon this as well. Seems like the stream is immediately closed, which is totally unexpected.