Created
August 5, 2023 19:05
-
-
Save saivert/e83ccc3ee732d81eba19740b65c358f7 to your computer and use it in GitHub Desktop.
Callback vs Future
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
act.connect_activate(clone!(@weak self as widget => move |_action, _param| { | |
let dlg = gtk::AlertDialog::builder().buttons(["Yes", "No"]).message("hi").build(); | |
let c = gio::Cancellable::new(); | |
dlg.choose(Some(widget.obj().as_ref()), Some(&c), |x| { | |
match x { | |
Ok(x) => { wp::info!("got {x}"); }, | |
Err(_) => { wp::log::warning!("Err in dlg result"); } | |
} | |
}); | |
// Or using a future: | |
// let f = async move { | |
// let dlg = gtk::AlertDialog::builder().buttons(["Yes", "No"]).message("hi").build(); | |
// match dlg.choose_future(Some(widget.obj().as_ref())).await { | |
// Ok(x) => { wp::info!("got {x}"); }, | |
// Err(_) => { wp::log::warning!("Err in dlg result"); } | |
// } | |
// }; | |
// glib::MainContext::default().spawn_local(f); | |
})); | |
self.obj().add_action(&act); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment