Files
tokio/tokio-stream/tests/time_throttle.rs
T

29 lines
649 B
Rust
Raw Normal View History

2019-12-14 09:06:41 +03:00
#![warn(rust_2018_idioms)]
2022-01-28 13:30:07 -03:00
#![cfg(all(feature = "time", feature = "sync", feature = "io-util"))]
2019-12-14 09:06:41 +03:00
2020-09-02 11:52:31 +02:00
use tokio::time;
2020-12-15 23:24:38 -05:00
use tokio_stream::StreamExt;
2019-12-14 09:06:41 +03:00
use tokio_test::*;
use std::time::Duration;
#[tokio::test]
async fn usage() {
time::pause();
2020-09-02 11:52:31 +02:00
let mut stream = task::spawn(futures::stream::repeat(()).throttle(Duration::from_millis(100)));
2019-12-14 09:06:41 +03:00
assert_ready!(stream.poll_next());
assert_pending!(stream.poll_next());
time::advance(Duration::from_millis(90)).await;
assert_pending!(stream.poll_next());
time::advance(Duration::from_millis(101)).await;
assert!(stream.is_woken());
assert_ready!(stream.poll_next());
}