Repository: seanmonstar/reqwest (language: rust)

Issue:
Improve async example - show multiple concurrent requests
As someone who isn't familiar with tokio, the reqwest [async example](https://github.com/seanmonstar/reqwest/blob/master/examples/async.rs) does not make it clear how to make multiple concurrent requests.

In particular, my use case is basically generating several URLs, making the requests concurrently (each request should save it's result to a shared results vector, or something similar), then processing the results once all of the requests have completed. 

I'm going to dive into the tokio documentation to try to figure this out, but any pointers would be appreciated. Once I've got it, would you be open to a PR to update the example? 


Discussion / hints:
I've updated the example code to make multiple requests, but I haven't been able to figure out how to use the [reqwest::unstable::async::Response json method](https://docs.rs/reqwest/*/reqwest/unstable/async/struct.Response.html#method.json) to deserialize the response. 

[A gist containing my progress](https://gist.github.com/rust-play/6d720f7277937a4b83fc45be4b628fe1)

edit - I found what feels like a hacky workaround that solves this problem (gist below). Any thoughts on a more idiomatic approach? 

https://gist.github.com/1f96977551644760f08ee543cffc1f06
I'd expect you would be able to use `response.json()` to get a future that deserializes to type you want. That can either be through type inference, or you can could use `response.json::<MyType>()`.
Thanks for the feedback. I think I've cleaned up the example as much as possible in [this gist](https://gist.github.com/JoshMcguigan/398377ab48d1c20f84efa2cabb224832). I'd be happy to open a PR to update the official example if you think that'd be helpful.
Sorry I let this slip! I think having a second async example with multiple requests sounds like a great idea! The code in the gist would need to be updated a little, but not by too much.

Fix patch:
diff --git a/examples/async_multiple_requests.rs b/examples/async_multiple_requests.rs
new file mode 100644
index 000000000..e5aafb71d
--- /dev/null
+++ b/examples/async_multiple_requests.rs
@@ -0,0 +1,55 @@
+#![deny(warnings)]
+
+extern crate futures;
+extern crate reqwest;
+extern crate tokio;
+extern crate serde;
+#[macro_use] extern crate serde_derive;
+extern crate serde_json;
+
+use futures::Future;
+use reqwest::async::{Client, Response};
+
+#[derive(Deserialize, Debug)]
+struct Slideshow {
+    title: String,
+    author: String,
+}
+
+#[derive(Deserialize, Debug)]
+struct SlideshowContainer {
+    slideshow: Slideshow,
+}
+
+fn fetch() -> impl Future<Item=(), Error=()> {
+    let client = Client::new();
+
+    let json = |mut res : Response | {
+        res.json::<SlideshowContainer>()
+    };
+
+    let request1 =
+        client
+            .get("https://httpbin.org/json")
+            .send()
+            .and_then(json);
+
+    let request2 =
+        client
+            .get("https://httpbin.org/json")
+            .send()
+            .and_then(json);
+
+    request1.join(request2)
+        .map(|(res1, res2)|{
+            println!("{:?}", res1);
+            println!("{:?}", res2);
+        })
+        .map_err(|err| {
+            println!("stdout error: {}", err);
+        })
+}
+
+fn main() {
+    tokio::run(fetch());
+}


Test patch: