Pipeline: remove submodule hack.

This commit is contained in:
Jordan Petridis 2018-01-16 14:37:51 +02:00
parent b3460b15a2
commit bf4f655ed2
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -7,42 +7,11 @@ use hyper_tls::HttpsConnector;
use futures::prelude::*; use futures::prelude::*;
use futures::future::*; use futures::future::*;
use errors::Error; use errors::*;
use Source; use Source;
// use Feed; // use Feed;
// Weird magic from #rust irc channel use std;
// kudos to remexre
fn collect_futures<F>(
futures: Vec<F>,
) -> Box<Future<Item = Vec<Result<F::Item, F::Error>>, Error = Error>>
where
F: 'static + Future,
<F as Future>::Item: 'static,
<F as Future>::Error: 'static,
{
Box::new(loop_fn((futures, vec![]), |(futures, mut done)| {
select_all(futures).then(|r| {
let (r, rest) = match r {
Ok((r, _, rest)) => (Ok(r), rest),
Err((r, _, rest)) => (Err(r), rest),
};
done.push(r);
if rest.len() == 0 {
Ok(Loop::Break(done))
} else {
Ok(Loop::Continue((rest, done)))
}
})
}))
}
pub use self::dirtyhack::pipeline;
// Use a submodule ot not polute the collect_futures definition with the errorchain Result<T>.
mod dirtyhack {
use super::*;
use errors::*;
/// The pipline to be run for indexing and updating a Podcast feed that originates from /// The pipline to be run for indexing and updating a Podcast feed that originates from
/// `Source.uri`. /// `Source.uri`.
@ -72,4 +41,29 @@ mod dirtyhack {
Ok(()) Ok(())
} }
// Weird magic from #rust irc channel
// kudos to remexre
fn collect_futures<F>(
futures: Vec<F>,
) -> Box<Future<Item = Vec<std::result::Result<F::Item, F::Error>>, Error = Error>>
where
F: 'static + Future,
<F as Future>::Item: 'static,
<F as Future>::Error: 'static,
{
Box::new(loop_fn((futures, vec![]), |(futures, mut done)| {
select_all(futures).then(|r| {
let (r, rest) = match r {
Ok((r, _, rest)) => (Ok(r), rest),
Err((r, _, rest)) => (Err(r), rest),
};
done.push(r);
if rest.len() == 0 {
Ok(Loop::Break(done))
} else {
Ok(Loop::Continue((rest, done)))
}
})
}))
} }