Created
August 2, 2018 16:15
-
-
Save pimeys/aece60291164903812ea975641961b69 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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