From 40b3a387547577720f289669d34a55254ecf9ce9 Mon Sep 17 00:00:00 2001 From: Stefan Kreutz Date: Wed, 7 Jun 2023 15:01:52 +0200 Subject: Revise ParallelIterator trait usage examples --- src/lib.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 1359ec6..f71965b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,14 +72,16 @@ pub trait ParallelIterator { /// use std::time::Duration; /// use parseq::ParallelIterator; /// - /// let mut iter = (0..3) + /// let mut iter = [3,2,1] + /// .into_iter() /// .map_parallel(|i| { - /// std::thread::sleep(Duration::from_millis((i % 3) * 10)); - /// i + /// // Insert heavy computation here ... + /// 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); /// ``` @@ -119,14 +121,15 @@ pub trait ParallelIterator { /// use std::time::Duration; /// use parseq::ParallelIterator; /// - /// let mut iter = (0..3) + /// let mut iter = [3,2,1] + /// .into_iter() /// .map_parallel_limit(2, 16, |i| { - /// 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); /// ``` -- cgit v1.2.3