From 8c376e1df2b16ddc221afc3ddeb19c57b1adb687 Mon Sep 17 00:00:00 2001 From: Lucy Date: Mon, 7 Feb 2022 11:13:13 -0500 Subject: [PATCH] `task::wait_for_local` can now return a value --- applets/cosmic-applet-network/src/task.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/applets/cosmic-applet-network/src/task.rs b/applets/cosmic-applet-network/src/task.rs index 61d79cf8..37078fbb 100644 --- a/applets/cosmic-applet-network/src/task.rs +++ b/applets/cosmic-applet-network/src/task.rs @@ -14,11 +14,14 @@ pub fn spawn_local + 'static>(future: F) { gtk4::glib::MainContext::default().spawn_local(future); } -pub async fn wait_for_local + 'static>(future: F) { - let (tx, rx) = oneshot::channel::<()>(); +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 { - future.await; - let _ = tx.send(()); + std::mem::drop(tx.send(future.await)); }); - std::mem::drop(rx.await); + rx.await.ok() }