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
38
39
use std::{future::poll_fn, task::Poll, thread};

use winmsg_executor::block_on;

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() {
    thread::spawn(|| {
        println!("thread hello");
        block_on(async {
            println!("thread async hello");
            poll_n_times(3).await;
            println!("thread async bye");
        })
        .unwrap();
        println!("thread bye");
    });

    println!("main hello");
    block_on(async {
        println!("main async hello");
        poll_n_times(3).await;
        println!("main async bye");
    })
    .unwrap();
    println!("main bye");
}