[fractal/fractal-next] Remove uneeded oneshots
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] Remove uneeded oneshots
- Date: Wed, 13 Oct 2021 10:03:59 +0000 (UTC)
commit 8ea3f3fae9926c52a33d115ef30ff5ecf37a8a75
Author: Julian Sparber <julian sparber net>
Date: Wed Oct 13 11:37:56 2021 +0200
Remove uneeded oneshots
When spawning a future on the tokio runtime we can use the handle to
obtain the result of the operation therefore the oneshots arn't needed.
src/components/auth_dialog.rs | 12 ++++++------
src/session/room/mod.rs | 10 ++++------
src/utils.rs | 6 ++----
3 files changed, 12 insertions(+), 16 deletions(-)
---
diff --git a/src/components/auth_dialog.rs b/src/components/auth_dialog.rs
index 44ed2a71..0ca84892 100644
--- a/src/components/auth_dialog.rs
+++ b/src/components/auth_dialog.rs
@@ -232,9 +232,8 @@ impl AuthDialog {
loop {
let callback_clone = callback.clone();
- let (sender, receiver) = futures::channel::oneshot::channel();
- RUNTIME.spawn(async move { sender.send(callback_clone(auth_data).await) });
- let response = receiver.await.unwrap();
+ let handle = RUNTIME.spawn(async move { callback_clone(auth_data).await });
+ let response = handle.await.unwrap();
let uiaa_info: UiaaInfo = match response {
Ok(result) => return Some(Ok(result)),
@@ -276,9 +275,10 @@ impl AuthDialog {
priv_.stack.set_visible_child_name("fallback");
let client = self.session().client();
- let (sender, receiver) = futures::channel::oneshot::channel();
- RUNTIME.spawn(async move { sender.send(client.homeserver().await) });
- let homeserver = receiver.await.unwrap();
+ let homeserver = RUNTIME
+ .spawn(async move { client.homeserver().await })
+ .await
+ .unwrap();
self.setup_fallback_page(
homeserver.as_str(),
flow.stages.first()?,
diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs
index 68a58ed2..fa35f3e1 100644
--- a/src/session/room/mod.rs
+++ b/src/session/room/mod.rs
@@ -887,9 +887,8 @@ impl Room {
let matrix_room = self.matrix_room();
if let MatrixRoom::Invited(matrix_room) = matrix_room {
- let (sender, receiver) = futures::channel::oneshot::channel();
- RUNTIME.spawn(async move { sender.send(matrix_room.accept_invitation().await) });
- match receiver.await.unwrap() {
+ let handle = RUNTIME.spawn(async move { matrix_room.accept_invitation().await });
+ match handle.await.unwrap() {
Ok(result) => Ok(result),
Err(error) => {
error!("Accepting invitation failed: {}", error);
@@ -918,9 +917,8 @@ impl Room {
let matrix_room = self.matrix_room();
if let MatrixRoom::Invited(matrix_room) = matrix_room {
- let (sender, receiver) = futures::channel::oneshot::channel();
- RUNTIME.spawn(async move { sender.send(matrix_room.reject_invitation().await) });
- match receiver.await.unwrap() {
+ let handle = RUNTIME.spawn(async move { matrix_room.reject_invitation().await });
+ match handle.await.unwrap() {
Ok(result) => Ok(result),
Err(error) => {
error!("Rejecting invitation failed: {}", error);
diff --git a/src/utils.rs b/src/utils.rs
index 9bc5622f..a1d1769f 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -47,13 +47,11 @@ pub fn do_async<
tokio_fut: F1,
glib_closure: FN,
) {
- let (sender, receiver) = futures::channel::oneshot::channel();
+ let handle = RUNTIME.spawn(async move { tokio_fut.await });
glib::MainContext::default().spawn_local_with_priority(priority, async move {
- glib_closure(receiver.await.unwrap()).await
+ glib_closure(handle.await.unwrap()).await
});
-
- RUNTIME.spawn(async move { sender.send(tokio_fut.await) });
}
/// Returns an expression looking up the given property on `object`.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]