task::wait_for_local can now return a value
This commit is contained in:
parent
8f170b9147
commit
8c376e1df2
1 changed files with 8 additions and 5 deletions
|
|
@ -14,11 +14,14 @@ pub fn spawn_local<F: Future<Output = ()> + 'static>(future: F) {
|
||||||
gtk4::glib::MainContext::default().spawn_local(future);
|
gtk4::glib::MainContext::default().spawn_local(future);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn wait_for_local<F: Future<Output = ()> + 'static>(future: F) {
|
pub async fn wait_for_local<O, F>(future: F) -> Option<O>
|
||||||
let (tx, rx) = oneshot::channel::<()>();
|
where
|
||||||
|
O: Send + 'static,
|
||||||
|
F: Future<Output = O> + Send + 'static,
|
||||||
|
{
|
||||||
|
let (tx, rx) = oneshot::channel::<O>();
|
||||||
gtk4::glib::MainContext::default().spawn_local(async move {
|
gtk4::glib::MainContext::default().spawn_local(async move {
|
||||||
future.await;
|
std::mem::drop(tx.send(future.await));
|
||||||
let _ = tx.send(());
|
|
||||||
});
|
});
|
||||||
std::mem::drop(rx.await);
|
rx.await.ok()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue