summaryrefslogtreecommitdiff
path: root/examples/join.rs
blob: f55f79f71faec6f9cd77d96c1f8101147f8687c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Since futures only executed when it is polled or awaited,
//! this example shows how to await multiple futures at the same time.
//! (Another way is spawning them and await the JoinHandle.)

#[monoio::main]
async fn main() {
    println!("directly await ready_now: {}", ready_now().await);

    let to_spawn = monoio::spawn(ready_now());
    println!("spawn await ready_now: {:?}", to_spawn.await);

    monoio::join!(ready_now(), ready_now());
    println!("monoio::join two tasks");
}

async fn ready_now() -> u8 {
    7
}