Function wait_ms

Source
pub async fn wait_ms(ms: u64)
Examples found in repository?
examples/runtime.rs (line 13)
12async fn print_something_after_ms(ms: u64) {
13    wait_ms(ms).await;
14    println!("something! :D");
15}
More examples
Hide additional examples
examples/recursion.rs (line 11)
10async fn print_something_after_ms(ms: u64) {
11    wait_ms(ms).await;
12    println!("something after {ms}ms! :D");
13    get_current_runtime()
14        .await
15        .push(print_something_after_ms(ms + 1));
16}
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}