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! {
319
319
Limit the amount of items yielded per timeslice in a stream.
320
320
321
321
# Examples
322
- ```ignore
322
+ ```
323
323
# fn main() { async_std::task::block_on(async {
324
324
#
325
+ use async_std::prelude::*;
325
326
use async_std::stream;
326
327
use std::time::Duration;
327
328
328
329
// 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 );
330
331
331
332
// throttle for 2 seconds
332
- let s = s.throttle(Duration::from_secs(2 ));
333
+ let mut s = s.throttle(Duration::from_millis(10 ));
333
334
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);
339
339
// with a pause of 2 seconds between each print
340
340
#
341
341
# }) }
You can’t perform that action at this time.
0 commit comments