1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::{future::poll_fn, task::Poll};

use winmsg_executor::{block_on, spawn};

async fn poll_n_times(mut n_poll: usize) {
    poll_fn(|cx| {
        println!("n_poll={n_poll}");
        if n_poll == 0 {
            Poll::Ready(())
        } else {
            n_poll -= 1;
            cx.waker().wake_by_ref();
            Poll::Pending
        }
    })
    .await;
}

fn main() {
    println!("hello");
    block_on(async {
        let task = spawn(async {
            println!("async hello 1");
            poll_n_times(3).await;
            println!("async bye 1");
            "async 1 result"
        });

        println!("async hello 2");
        poll_n_times(2).await;
        println!("async bye 2");

        println!("{}", task.await);
    })
    .unwrap();
    println!("bye");
}