Skip to content

Instantly share code, notes, and snippets.

@saivert
Created August 5, 2023 19:05
Show Gist options
  • Save saivert/e83ccc3ee732d81eba19740b65c358f7 to your computer and use it in GitHub Desktop.
Save saivert/e83ccc3ee732d81eba19740b65c358f7 to your computer and use it in GitHub Desktop.
Callback vs Future
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