From 5f62e3210e70db61107afc9a1a69684fe31f1eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Fri, 25 Aug 2017 13:06:50 +0200 Subject: [PATCH] Making all bk commands in the same thread --- src/backend.rs | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/backend.rs b/src/backend.rs index 1418517f..98b1a747 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -373,16 +373,14 @@ impl Backend { let userid = self.data.lock().unwrap().user_id.clone(); let tx = self.tx.clone(); - thread::spawn(move || { - match get_user_avatar(&baseu, &userid) { - Ok(fname) => { - tx.send(BKResponse::Avatar(fname)).unwrap(); - }, - Err(err) => { - tx.send(BKResponse::AvatarError(err)).unwrap(); - } + match get_user_avatar(&baseu, &userid) { + Ok(fname) => { + tx.send(BKResponse::Avatar(fname)).unwrap(); + }, + Err(err) => { + tx.send(BKResponse::AvatarError(err)).unwrap(); } - }); + }; Ok(()) } @@ -564,16 +562,14 @@ impl Backend { let baseu = self.get_base_url()?; let tx = self.tx.clone(); - thread::spawn(move || { - match thumb!(&baseu, &avatar_url) { - Ok(fname) => { - tx.send(BKResponse::RoomMemberAvatar(memberid, fname)).unwrap(); - }, - Err(err) => { - tx.send(BKResponse::RoomMemberAvatarError(err)).unwrap(); - } + match thumb!(&baseu, &avatar_url) { + Ok(fname) => { + tx.send(BKResponse::RoomMemberAvatar(memberid, fname)).unwrap(); + }, + Err(err) => { + tx.send(BKResponse::RoomMemberAvatarError(err)).unwrap(); } - }); + } Ok(()) } @@ -588,10 +584,8 @@ impl Backend { let base = self.get_base_url()?; let u = url.clone(); - thread::spawn(move || { - let fname = thumb!(&base, &u).unwrap(); - tx.send(fname).unwrap(); - }); + let fname = thumb!(&base, &u)?; + tx.send(fname).unwrap(); Ok(()) } @@ -600,12 +594,10 @@ impl Backend { let baseu = self.get_base_url()?; let u = String::from(uid); - thread::spawn(move || { - match get_user_avatar(&baseu, &u) { - Ok(fname) => { tx.send(fname).unwrap(); }, - Err(_) => { tx.send(String::from("")).unwrap(); } - }; - }); + match get_user_avatar(&baseu, &u) { + Ok(fname) => { tx.send(fname).unwrap(); }, + Err(_) => { tx.send(String::from("")).unwrap(); } + }; Ok(()) }