mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-19 20:13:51 +00:00
Change throttle test to run in milliseconds
This commit is contained in:
parent
ef958f0408
commit
88cbf2c119
1 changed files with 8 additions and 8 deletions
|
@ -319,23 +319,23 @@ extension_trait! {
|
||||||
Limit the amount of items yielded per timeslice in a stream.
|
Limit the amount of items yielded per timeslice in a stream.
|
||||||
|
|
||||||
# Examples
|
# Examples
|
||||||
```ignore
|
```
|
||||||
# fn main() { async_std::task::block_on(async {
|
# fn main() { async_std::task::block_on(async {
|
||||||
#
|
#
|
||||||
|
use async_std::prelude::*;
|
||||||
use async_std::stream;
|
use async_std::stream;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
// emit value every 1 second
|
// emit value every 1 second
|
||||||
let s = stream::interval(Duration::from_nanos(1000000)).enumerate();
|
let s = stream::interval(Duration::from_millis(5)).enumerate().take(3);
|
||||||
|
|
||||||
// throttle for 2 seconds
|
// throttle for 2 seconds
|
||||||
let s = s.throttle(Duration::from_secs(2));
|
let mut s = s.throttle(Duration::from_millis(10));
|
||||||
|
|
||||||
s.for_each(|(n, _)| {
|
assert_eq!(s.next().await, Some((0, ())));
|
||||||
dbg!(n);
|
assert_eq!(s.next().await, Some((1, ())));
|
||||||
})
|
assert_eq!(s.next().await, Some((2, ())));
|
||||||
.await;
|
assert_eq!(s.next().await, None);
|
||||||
// => 0 .. 1 .. 2 .. 3
|
|
||||||
// with a pause of 2 seconds between each print
|
// with a pause of 2 seconds between each print
|
||||||
#
|
#
|
||||||
# }) }
|
# }) }
|
||||||
|
|
Loading…
Reference in a new issue