Browse Source

use different PRIORITIES for async tasks

merge-requests/1327/merge
Julian Sparber 5 years ago
parent
commit
aed7f87116
  1. 2
      src/session/mod.rs
  2. 4
      src/session/room/room.rs
  3. 6
      src/utils.rs

2
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))

4
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

6
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) });
}

Loading…
Cancel
Save