Skip to content

Instantly share code, notes, and snippets.

@pimeys
Created August 2, 2018 16:15
Show Gist options
  • Save pimeys/aece60291164903812ea975641961b69 to your computer and use it in GitHub Desktop.
Save pimeys/aece60291164903812ea975641961b69 to your computer and use it in GitHub Desktop.
extern crate hyper;
extern crate futures;
extern crate tokio;
use hyper::{Client};
use hyper::rt::{Future, Stream};
use futures::future::{join_all};
fn main() {
let mut i = 7;
let mut futures = vec![];
while i != 0 {
let fut = Client::new()
.get("http://httpbin.org/ip".parse().unwrap())
.and_then(|res| {
println!("Response: {}", res.status());
println!("Headers: {:#?}", res.headers());
res.into_body().concat2()
});
futures.push(fut);
i -= 1;
}
let work = join_all(futures)
.map_err(|error| {
println!("Error: {:?}", error);
})
.map(|res| {
println!("Got successful result: {:?}", res);
});
tokio::run(work)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment