Skip to content

Instantly share code, notes, and snippets.

@boxofrox
Forked from ob/gist:11961f2f82fc7001c71444d261352f94
Last active May 23, 2017 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxofrox/d7616ab0ccfe821572628f0451bfa7eb to your computer and use it in GitHub Desktop.
Save boxofrox/d7616ab0ccfe821572628f0451bfa7eb to your computer and use it in GitHub Desktop.
tokio-rs : two url example -> many url example
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