Function microasync_rt::wait_ms

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