authenticator/
utils.rs

1use crate::models::RUNTIME;
2
3pub fn spawn_tokio_blocking<F>(fut: F) -> F::Output
4where
5    F: std::future::Future + Send + 'static,
6    F::Output: Send + 'static,
7{
8    let (sender, receiver) = tokio::sync::oneshot::channel();
9
10    RUNTIME.spawn(async {
11        let response = fut.await;
12        sender.send(response)
13    });
14    receiver.blocking_recv().unwrap()
15}
16
17pub async fn spawn_tokio<F>(fut: F) -> F::Output
18where
19    F: std::future::Future + Send + 'static,
20    F::Output: Send + 'static,
21{
22    let (sender, receiver) = tokio::sync::oneshot::channel();
23
24    RUNTIME.spawn(async {
25        let response = fut.await;
26        sender.send(response)
27    });
28    receiver.await.unwrap()
29}
30
31pub fn spawn<F>(fut: F)
32where
33    F: std::future::Future + 'static,
34{
35    let ctx = gtk::glib::MainContext::default();
36    ctx.spawn_local(async move {
37        fut.await;
38    });
39}