diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index d865cfb..a648f9b 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -26,15 +26,14 @@ extern crate hammond_downloader; extern crate humansize; extern crate loggerv; extern crate open; +extern crate rayon; extern crate regex; extern crate reqwest; extern crate send_cell; extern crate serde_json; extern crate take_mut; extern crate url; -// extern crate rayon; -// use rayon::prelude::*; use log::Level; use gtk::prelude::*; diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 5c6c70f..92bae9f 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -7,6 +7,7 @@ use gtk; use gtk::prelude::*; use failure::Error; +use rayon; use regex::Regex; use reqwest; use send_cell::SendCell; @@ -132,6 +133,7 @@ fn refresh_feed(source: Option>, sender: Sender) -> Result<( lazy_static! { static ref CACHED_PIXBUFS: RwLock>>> = { RwLock::new(HashMap::new()) }; + static ref THREADPOOL: rayon::ThreadPool = rayon::ThreadPoolBuilder::new().build().unwrap(); } // Since gdk_pixbuf::Pixbuf is refference counted and every episode, @@ -161,12 +163,12 @@ pub fn set_image_from_path( let (sender, receiver) = channel(); let pd_ = pd.clone(); - thread::spawn(move || { + THREADPOOL.spawn(move || { sender.send(downloader::cache_image(&pd_)).unwrap(); }); let image = image.clone(); - gtk::timeout_add(200, move || { + gtk::timeout_add(50, move || { if let Ok(path) = receiver.try_recv() { if let Ok(path) = path { if let Ok(px) =