Add task:wait_for_local
This commit is contained in:
parent
585946bbfa
commit
7941c2f6a3
1 changed files with 10 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
pub fn spawn<O, F>(future: F) -> tokio::task::JoinHandle<O>
|
pub fn spawn<O, F>(future: F) -> tokio::task::JoinHandle<O>
|
||||||
where
|
where
|
||||||
|
|
@ -12,3 +13,12 @@ where
|
||||||
pub fn spawn_local<F: Future<Output = ()> + 'static>(future: F) {
|
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) {
|
||||||
|
let (tx, rx) = oneshot::channel::<()>();
|
||||||
|
gtk4::glib::MainContext::default().spawn_local(async move {
|
||||||
|
future.await;
|
||||||
|
let _ = tx.send(());
|
||||||
|
});
|
||||||
|
std::mem::drop(rx.await);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue