diff options
author | Stefan Kreutz <mail@skreutz.com> | 2023-03-25 17:41:04 +0100 |
---|---|---|
committer | Stefan Kreutz <mail@skreutz.com> | 2023-03-25 17:41:04 +0100 |
commit | e73ccbe573a87665eed879a1f08d49e60031afa8 (patch) | |
tree | 88ad91a68a1cffd6410e45417eb8ab926fe7c7d2 /posts/parseq.md | |
parent | 4291151857af5da5a7bcb50cc69133af9443ac2c (diff) | |
download | blog-e73ccbe573a87665eed879a1f08d49e60031afa8.tar |
Revise parseq example
Diffstat (limited to 'posts/parseq.md')
-rw-r--r-- | posts/parseq.md | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/posts/parseq.md b/posts/parseq.md index 2e3b607..eb7c159 100644 --- a/posts/parseq.md +++ b/posts/parseq.md @@ -2,6 +2,7 @@ title: "Parseq" description: "A parallel sequential iterator for Rust." published: 2022-12-20 +updated: 2023-03-25 --- I've published my own parallel sequential iterator library for Rust, [Parseq](https://crates.io/crates/parseq). @@ -11,16 +12,16 @@ It's a drop-in-replacement for the standard [`map`](https://doc.rust-lang.org/st use std::time::Duration; use parseq::ParallelIterator; - let mut iter = (0..3) + let mut iter = [3,2,1] .into_iter() .map_parallel(|i| { // Insert heavy computation here ... - std::thread::sleep(Duration::from_millis((i % 3) * 10)); - i + std::thread::sleep(Duration::from_millis(100*i)); + 2*i }); - - assert_eq!(iter.next(), Some(0)); - assert_eq!(iter.next(), Some(1)); + + assert_eq!(iter.next(), Some(6)); + assert_eq!(iter.next(), Some(4)); assert_eq!(iter.next(), Some(2)); assert_eq!(iter.next(), None); |