Skip to content

Instantly share code, notes, and snippets.

@ob
Created May 23, 2017 23:10
Show Gist options
  • Save ob/11961f2f82fc7001c71444d261352f94 to your computer and use it in GitHub Desktop.
Save ob/11961f2f82fc7001c71444d261352f94 to your computer and use it in GitHub Desktop.
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;
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 : Vec<_> = urls.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)
})
.collect();
let head = sessions.first().unwrap();
let tail = &sessions[1..];
let req = tail.iter().fold(head, |acc, item| {
acc.join(item)
});
let results = lp.run(req).unwrap();
for r in results {
println!("{}", r.response_code());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment