pub async fn wait_ms(ms: u64)
Examples found in repository?
More examples
examples/http.rs (line 16)
9fn main() {
10 // Connecting cannot be done async (for now), so we won't include that in the timing.
11 let tcp = TcpStream::connect(("google.com", 80)).expect("connection refused");
12 let start = SystemTime::now();
13 println!(
14 "{}",
15 sync(join!(request("google.com", tcp, "GET /"), async {
16 wait_ms(1000).await;
17 "".to_owned()
18 }))[0]
19 );
20 println!("Took {}ms.", start.elapsed().unwrap().as_millis());
21}
examples/tcp.rs (line 40)
28async fn handle((mut stream, _): (TcpStream, SocketAddr)) {
29 let mut buf = [0_u8; 10];
30 loop {
31 let n = stream.read(&mut buf).await.unwrap();
32 if n == 0 {
33 break;
34 }
35 print!(
36 "{}",
37 buf[0..n].iter().map(|x| *x as char).collect::<String>()
38 );
39 io::stdout().flush().unwrap();
40 wait_ms(100).await; // Delay so multiple connections can accumulate, for demonstration
41 // purposes.
42 }
43}