[fractal/fractal-next] use different PRIORITIES for async tasks
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] use different PRIORITIES for async tasks
- Date: Tue, 11 May 2021 21:29:52 +0000 (UTC)
commit aed7f871160a098d2ccee19cdf829216962b86d9
Author: Julian Sparber <julian sparber net>
Date: Tue May 11 16:17:36 2021 +0200
use different PRIORITIES for async tasks
src/session/mod.rs | 2 ++
src/session/room/room.rs | 4 ++++
src/utils.rs | 6 ++++--
3 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 34afd376..5981a315 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -183,6 +183,7 @@ impl Session {
);
do_async(
+ glib::PRIORITY_DEFAULT_IDLE,
async move {
let passphrase: String = {
let mut rng = thread_rng();
@@ -228,6 +229,7 @@ impl Session {
pub fn login_with_previous_session(&self, session: StoredSession) {
do_async(
+ glib::PRIORITY_DEFAULT_IDLE,
async move {
let config = ClientConfig::new()
.request_config(RequestConfig::new().retry_limit(2))
diff --git a/src/session/room/room.rs b/src/session/room/room.rs
index bf591371..0b7e3d70 100644
--- a/src/session/room/room.rs
+++ b/src/session/room/room.rs
@@ -229,6 +229,7 @@ impl Room {
match matrix_room {
MatrixRoom::Joined(_) => {
do_async(
+ glib::PRIORITY_DEFAULT_IDLE,
async move { matrix_room.tags().await },
clone!(@weak self as obj => move |tags_result| async move {
let mut category = CategoryType::Normal;
@@ -297,6 +298,7 @@ impl Room {
let priv_ = imp::Room::from_instance(&self);
let matrix_room = priv_.matrix_room.get().unwrap().clone();
do_async(
+ glib::PRIORITY_DEFAULT_IDLE,
async move { matrix_room.display_name().await },
clone!(@weak self as obj => move |display_name| async move {
// FIXME: We should retry to if the request failed
@@ -375,6 +377,7 @@ impl Room {
let matrix_room = priv_.matrix_room.get().unwrap().clone();
do_async(
+ glib::PRIORITY_LOW,
async move { matrix_room.active_members().await },
clone!(@weak self as obj => move |members| async move {
// FIXME: We should retry to load the room members if the request failed
@@ -471,6 +474,7 @@ impl Room {
.append_pending(AnyRoomEvent::Message(event));
do_async(
+ glib::PRIORITY_DEFAULT_IDLE,
async move { matrix_room.send(content, Some(txn_id)).await },
clone!(@weak self as obj => move |result| async move {
// FIXME: We should retry the request if it fails
diff --git a/src/utils.rs b/src/utils.rs
index e8930bcb..1f1f7e88 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -41,13 +41,15 @@ pub fn do_async<
F2: Future<Output = ()> + 'static,
FN: FnOnce(R) -> F2 + 'static,
(
+ priority: glib::source::Priority,
tokio_fut: F1,
glib_closure: FN,
) {
let (sender, receiver) = futures::channel::oneshot::channel();
- glib::MainContext::default()
- .spawn_local(async move { glib_closure(receiver.await.unwrap()).await });
+ glib::MainContext::default().spawn_local_with_priority(priority, async move {
+ glib_closure(receiver.await.unwrap()).await
+ });
RUNTIME.spawn(async move { sender.send(tokio_fut.await) });
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]