File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -319,23 +319,23 @@ extension_trait! {
319319 Limit the amount of items yielded per timeslice in a stream.
320320
321321 # Examples
322- ```ignore
322+ ```
323323 # fn main() { async_std::task::block_on(async {
324324 #
325+ use async_std::prelude::*;
325326 use async_std::stream;
326327 use std::time::Duration;
327328
328329 // emit value every 1 second
329- let s = stream::interval(Duration::from_nanos(1000000 )).enumerate();
330+ let s = stream::interval(Duration::from_millis(5 )).enumerate().take(3 );
330331
331332 // throttle for 2 seconds
332- let s = s.throttle(Duration::from_secs(2 ));
333+ let mut s = s.throttle(Duration::from_millis(10 ));
333334
334- s.for_each(|(n, _)| {
335- dbg!(n);
336- })
337- .await;
338- // => 0 .. 1 .. 2 .. 3
335+ assert_eq!(s.next().await, Some((0, ())));
336+ assert_eq!(s.next().await, Some((1, ())));
337+ assert_eq!(s.next().await, Some((2, ())));
338+ assert_eq!(s.next().await, None);
339339 // with a pause of 2 seconds between each print
340340 #
341341 # }) }
You can’t perform that action at this time.
0 commit comments