Something Something futures.
This commit is contained in:
parent
8e367b7e86
commit
771b7b3804
@ -20,6 +20,7 @@
|
|||||||
#![deny(missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts)]
|
#![deny(missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts)]
|
||||||
// FIXME: uncomment
|
// FIXME: uncomment
|
||||||
// unused_extern_crates, unused)]
|
// unused_extern_crates, unused)]
|
||||||
|
// #![feature(conservative_impl_trait)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
|
|||||||
@ -1,19 +1,17 @@
|
|||||||
extern crate futures;
|
use hyper;
|
||||||
extern crate hyper;
|
|
||||||
extern crate tokio_core;
|
|
||||||
|
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use futures::{Future, Stream};
|
use futures::{Future, Stream};
|
||||||
// use futures::future::join_all;
|
|
||||||
use hyper::Client;
|
use hyper::Client;
|
||||||
use hyper::client::HttpConnector;
|
use hyper::client::HttpConnector;
|
||||||
use hyper::Method;
|
use hyper::Method;
|
||||||
use hyper::Uri;
|
use hyper::Uri;
|
||||||
use tokio_core::reactor::Core;
|
use tokio_core::reactor::Core;
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
use rss;
|
||||||
// use errors::*;
|
// use errors::*;
|
||||||
// use hyper::header::{ETag, LastModified};
|
// use hyper::header::{ETag, LastModified};
|
||||||
|
// use futures::future::join_all;
|
||||||
|
|
||||||
use Source;
|
use Source;
|
||||||
|
|
||||||
@ -64,11 +62,21 @@ fn req_constructor(
|
|||||||
Box::new(work)
|
Box::new(work)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn res_to_channel(res: hyper::Response) -> Box<Future<Item = rss::Channel, Error = hyper::Error>> {
|
||||||
|
let chan = res.body().concat2().map(|x| x.into_iter()).map(|iter| {
|
||||||
|
let utf_8_bytes = iter.collect::<Vec<u8>>();
|
||||||
|
let buf = String::from_utf8_lossy(&utf_8_bytes).into_owned();
|
||||||
|
rss::Channel::from_str(&buf).unwrap()
|
||||||
|
});
|
||||||
|
// .map_err(|_| ());
|
||||||
|
Box::new(chan)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures::future::result;
|
// use futures::future::result;
|
||||||
use rss::Channel;
|
|
||||||
|
|
||||||
use database::truncate_db;
|
use database::truncate_db;
|
||||||
use Source;
|
use Source;
|
||||||
@ -92,19 +100,14 @@ mod tests {
|
|||||||
|
|
||||||
let channel = req_constructor(&mut client, &mut source)
|
let channel = req_constructor(&mut client, &mut source)
|
||||||
.map(|res| {
|
.map(|res| {
|
||||||
info!("Status: {}", res.status());
|
println!("Status: {}", res.status());
|
||||||
source.update_etag2(&res);
|
source.update_etag2(&res).unwrap();
|
||||||
res
|
res
|
||||||
})
|
})
|
||||||
.and_then(|res| res.body().concat2())
|
.and_then(|res| res_to_channel(res));
|
||||||
.map(|concat2| concat2.into_iter())
|
|
||||||
.map(|iter| {
|
|
||||||
let utf_8_bytes = iter.collect::<Vec<u8>>();
|
|
||||||
let buf = String::from_utf8_lossy(&utf_8_bytes).into_owned();
|
|
||||||
Channel::from_str(&buf).unwrap()
|
|
||||||
});
|
|
||||||
|
|
||||||
let chan = core.run(channel).unwrap();
|
let chan = core.run(channel).unwrap();
|
||||||
|
// let c = chan.wait().unwrap();
|
||||||
println!("{:?}", chan);
|
println!("{:?}", chan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user