Skip to main content

async_wait/
main.rs

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