From 822deb28678597c59a08c7d223eb9bbe27648558 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 28 Aug 2018 20:43:45 +0300 Subject: [PATCH] Utils: do not block the cover_dl registry Accidently after f21398357bcc when a download would start, it would lock the cover_dl_registry hashmap till it had finished. Since the registry.read() happens on the main thread this would cause the UI to block until the download was and the mutex guard from the download thread dropped. --- podcasts-gtk/src/utils.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/podcasts-gtk/src/utils.rs b/podcasts-gtk/src/utils.rs index 29ef696..3a9553d 100644 --- a/podcasts-gtk/src/utils.rs +++ b/podcasts-gtk/src/utils.rs @@ -288,9 +288,14 @@ pub(crate) fn set_image_from_path( THREADPOOL.spawn(move || { if let Ok(mut guard) = COVER_DL_REGISTRY.write() { guard.insert(show_id); - if let Ok(pd) = dbqueries::get_podcast_cover_from_id(show_id) { - sender.send(downloader::cache_image(&pd)); - } + } + + // This operation is polling and will block the thread till the download is finished + if let Ok(pd) = dbqueries::get_podcast_cover_from_id(show_id) { + sender.send(downloader::cache_image(&pd)); + } + + if let Ok(mut guard) = COVER_DL_REGISTRY.write() { guard.remove(&show_id); } });