Debian Codegraph @

third_party/rust/tokio-stream/tests/time_throttle.rs

raw
1 #![warn(rust_2018_idioms)]
2 #![cfg(all(feature = "time", feature = "sync", feature = "io-util"))]
3
4 use tokio::time;
5 use tokio_stream::StreamExt;
6 use tokio_test::*;
7
8 use std::time::Duration;
9
10 #[tokio::test]
11 async fn usage() {
12 time::pause();
13
14 let mut stream = task::spawn(futures::stream::repeat(()).throttle(Duration::from_millis(100)));
15
16 assert_ready!(stream.poll_next());
17 assert_pending!(stream.poll_next());
18
19 time::advance(Duration::from_millis(90)).await;
20
21 assert_pending!(stream.poll_next());
22
23 time::advance(Duration::from_millis(101)).await;
24
25 assert!(stream.is_woken());
26
27 assert_ready!(stream.poll_next());
28 }