Skip to content

Instantly share code, notes, and snippets.

@syntheticsh
Last active August 2, 2018 14:16
Show Gist options
  • Select an option

  • Save syntheticsh/2aba981ee10898a09be1cc3a4fc2ce35 to your computer and use it in GitHub Desktop.

Select an option

Save syntheticsh/2aba981ee10898a09be1cc3a4fc2ce35 to your computer and use it in GitHub Desktop.
extern crate hyper;
extern crate futures;
extern crate tokio;
use hyper::{Client, Response, Body};
use hyper::rt::{Future, Stream};
use futures::future::join_all;
fn main() {
let client = Client::new();
let closure = |res: Response<Body>| {
println!("Response: {}", res.status());
println!("Headers: {:#?}", res.headers());
res.into_body().concat2()
};
let mut i = 7;
let mut futures = vec![];
while i != 0 {
let fut = client
.get("http://httpbin.org/ip".parse().unwrap())
.and_then(closure);
futures.push(fut);
i -= 1;
}
let work = join_all(futures);
tokio::run(work)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment