basic/
basic.rs

1use std::{future::poll_fn, task::Poll};
2
3use winmsg_executor::{block_on, spawn_local};
4
5async fn poll_n_times(mut n_poll: usize) {
6    poll_fn(|cx| {
7        println!("n_poll={n_poll}");
8        if n_poll == 0 {
9            Poll::Ready(())
10        } else {
11            n_poll -= 1;
12            cx.waker().wake_by_ref();
13            Poll::Pending
14        }
15    })
16    .await;
17}
18
19fn main() {
20    println!("hello");
21    block_on(async {
22        let task = spawn_local(async {
23            println!("async hello 1");
24            poll_n_times(3).await;
25            println!("async bye 1");
26            "async 1 result"
27        });
28
29        println!("async hello 2");
30        poll_n_times(2).await;
31        println!("async bye 2");
32
33        println!("{}", task.await);
34    });
35    println!("bye");
36}