Skip to content

Commit 6992955

Browse files
swsnrbilelmoussaoui
authored andcommitted
Add helper to return result from a future
1 parent d0c8c47 commit 6992955

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

gio/src/dbus_method_invocation.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,25 @@ impl DBusMethodInvocation {
4545
Err(error) => self.return_gerror(error),
4646
}
4747
}
48+
49+
// rustdoc-stripper-ignore-next
50+
/// Return an async result for this invocation.
51+
///
52+
/// Spawn the given future on the thread-default main context, and return the
53+
/// the result with [`return_result`]. Specifically, if a variant is returned
54+
/// that is not a tuple it is automatically wrapped into a tuple.
55+
///
56+
/// The given `Future` does not have to be `Send`.
57+
///
58+
/// This can be called only from the thread where the main context is running, e.g.
59+
/// from any other `Future` that is executed on this main context, or after calling
60+
/// `with_thread_default` or `acquire` on the main context.
61+
pub fn return_future_local<F>(self, f: F) -> glib::JoinHandle<()>
62+
where
63+
F: std::future::Future<Output = Result<Option<glib::Variant>, glib::Error>> + 'static,
64+
{
65+
glib::spawn_future_local(async move {
66+
self.return_result(f.await);
67+
})
68+
}
4869
}

0 commit comments

Comments
 (0)