From 457e43978f4f4ed8926a14d25fb22465e91ee7e2 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 23 Jan 2018 19:07:11 +0200 Subject: [PATCH] Pipeline: Fix a panic if the list of futures was 0. --- hammond-data/src/pipeline.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hammond-data/src/pipeline.rs b/hammond-data/src/pipeline.rs index 42205a3..07ff05c 100644 --- a/hammond-data/src/pipeline.rs +++ b/hammond-data/src/pipeline.rs @@ -45,7 +45,6 @@ macro_rules! clone { /// Convert `rss::Channel` into Feed -> Index Podcast -> Index Episodes. pub fn pipeline>(sources: S, ignore_etags: bool) -> Result<()> { let pool = CpuPool::new_num_cpus(); - let mut core = Core::new()?; let handle = core.handle(); let client = Client::configure() @@ -53,15 +52,19 @@ pub fn pipeline>(sources: S, ignore_etags: bool) .connector(HttpsConnector::new(4, &handle)?) .build(&handle); - let list = sources + let list: Vec<_> = sources .into_iter() .map(clone!(pool => move |s| s.into_feed(&client, pool.clone(), ignore_etags))) .map(|fut| fut.and_then(clone!(pool => move |feed| pool.clone().spawn(feed.index())))) .map(|fut| fut.map(|_| ()).map_err(|err| error!("Error: {}", err))) .collect(); - // Thats not really concurrent yet I think. - core.run(collect_futures(list))?; + // TODO: this could be moved at the start of the function. + if !list.is_empty() { + // Thats not really concurrent yet I think. + core.run(collect_futures(list))?; + } + Ok(()) }