Lazy_load: move to utils module and make it public.

This commit is contained in:
Jordan Petridis 2018-04-07 05:53:13 +03:00 committed by Merge Bot, Bors Wannabe
parent 4b4f5c39d4
commit 29cf5940f5
2 changed files with 19 additions and 19 deletions

View File

@ -4,6 +4,7 @@ use gdk_pixbuf::Pixbuf;
use gio::{Settings, SettingsExt};
use glib;
use gtk;
use gtk::{IsA, Widget};
use gtk::prelude::*;
use failure::Error;
@ -30,6 +31,23 @@ use app::Action;
use chrono::Duration;
use chrono::prelude::*;
pub fn lazy_load<T, C, F, W>(data: T, container: C, mut contructor: F)
where
T: IntoIterator + 'static,
T::Item: 'static,
C: ContainerExt + 'static,
F: FnMut(T::Item) -> W + 'static,
W: IsA<Widget>,
{
let mut data = data.into_iter();
gtk::idle_add(move || {
data.next()
.map(|x| container.add(&contructor(x)))
.map(|_| glib::Continue(true))
.unwrap_or(glib::Continue(false))
});
}
lazy_static! {
static ref IGNORESHOWS: Arc<Mutex<HashSet<i32>>> = Arc::new(Mutex::new(HashSet::new()));
}

View File

@ -14,6 +14,7 @@ use hammond_data::utils::get_download_folder;
use app::Action;
use manager;
use utils::lazy_load;
use widgets::episode_states::*;
use std::cell::RefCell;
@ -392,22 +393,3 @@ pub fn episodes_listbox(pd: Arc<Podcast>, sender: Sender<Action>) -> Result<gtk:
Ok(list)
}
use gtk::{IsA, Widget};
fn lazy_load<T, C, F, W>(data: T, container: C, mut contructor: F)
where
T: IntoIterator + 'static,
T::Item: 'static,
C: ContainerExt + 'static,
F: FnMut(T::Item) -> W + 'static,
W: IsA<Widget>,
{
let mut data = data.into_iter();
gtk::idle_add(move || {
data.next()
.map(|x| container.add(&contructor(x)))
.map(|_| glib::Continue(true))
.unwrap_or(glib::Continue(false))
});
}