-
-
Save boxofrox/d7616ab0ccfe821572628f0451bfa7eb to your computer and use it in GitHub Desktop.
tokio-rs : two url example -> many url example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate curl; | |
extern crate futures; | |
extern crate time; | |
extern crate tokio_core; | |
extern crate tokio_curl; | |
extern crate tokio_timer; | |
use curl::easy::Easy; | |
use futures::{Future, Stream}; | |
use futures::stream::futures_unordered; | |
use time::PreciseTime; | |
use tokio_core::reactor::Core; | |
use tokio_curl::Perform; | |
use tokio_curl::Session; | |
fn main() { | |
let mut lp = Core::new().unwrap(); | |
let session = Session::new(lp.handle()); | |
let urls = ["http://www.github.com", | |
"http://google.com", | |
"http://apple.com"]; | |
let sessions = urls.into_iter() | |
.map(|url| { | |
let mut ret = Easy::new(); | |
ret.get(true).unwrap(); | |
ret.url(url).unwrap(); | |
ret.write_function(|data| Ok(data.len())).unwrap(); | |
ret | |
}) | |
.map(|s| session.perform(s)); | |
let req = futures_unordered(sessions).and_then(|mut result| { | |
println!("{:?}", result.response_code()); | |
Ok(()) | |
}); | |
lp.run(req.for_each(|_| Ok(()))).unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment