async_wait/
main.rs

1use {
2    crate::common::protocols::wayland::{wl_callback::WlCallback, wl_display::WlDisplay},
3    wl_client::{Libwayland, Queue, proxy},
4};
5
6#[path = "../common/mod.rs"]
7mod common;
8
9#[tokio::main(flavor = "current_thread")]
10async fn main() {
11    let lib = Libwayland::open().unwrap();
12    let con = lib.connect_to_default_display().unwrap();
13    let queue = con.create_local_queue(c"async-wait");
14
15    create_sync(&queue, 1);
16
17    loop {
18        queue.wait_for_events().await.unwrap();
19        queue.dispatch_pending().unwrap();
20    }
21}
22
23fn create_sync(queue: &Queue, n: u64) {
24    let sync = queue.display::<WlDisplay>().sync();
25    proxy::set_event_handler(
26        &sync.clone(),
27        WlCallback::on_done(move |_, _| {
28            println!("done! ({n})");
29            proxy::destroy(&sync);
30            create_sync(proxy::queue(&sync), n + 1);
31        }),
32    );
33}