// SPDX-License-Identifier: GPL-3.0-or-later use std::future::Future; use tokio::sync::oneshot; pub fn spawn(future: F) -> tokio::task::JoinHandle where F: Future + Send + 'static, O: Send + 'static, { crate::RT.spawn(future) } pub fn block_on(future: F) -> O where F: Future + Send + 'static, O: Send + 'static, { crate::RT.block_on(future) } pub fn spawn_local + 'static>(future: F) { gtk4::glib::MainContext::default().spawn_local(future); } pub async fn wait_for_local(future: F) -> Option where O: Send + 'static, F: Future + Send + 'static, { let (tx, rx) = oneshot::channel::(); gtk4::glib::MainContext::default().spawn_local(async move { std::mem::drop(tx.send(future.await)); }); rx.await.ok() }