refactor(lib): convert to futures 0.2.0-beta (#1470)

This commit is contained in:
Sam Rijs
2018-03-30 07:32:44 +11:00
committed by Sean McArthur
parent 5db85316a1
commit a12f7beed9
34 changed files with 1366 additions and 1347 deletions

View File

@@ -5,7 +5,7 @@ extern crate pretty_env_logger;
extern crate tokio;
extern crate url;
use futures::{Future, Stream};
use futures::{Future, FutureExt, StreamExt};
use futures::future::lazy;
use hyper::{Body, Method, Request, Response, StatusCode};
@@ -32,7 +32,7 @@ impl Service for ParamExample {
Box::new(futures::future::ok(Response::new(INDEX.into())))
},
(&Method::POST, "/post") => {
Box::new(req.into_parts().1.into_stream().concat2().map(|b| {
Box::new(req.into_parts().1.into_stream().concat().map(|b| {
// Parse the request body. form_urlencoded::parse
// always succeeds, but in general parsing may
// fail (for example, an invalid post of json), so
@@ -98,9 +98,11 @@ fn main() {
pretty_env_logger::init();
let addr = "127.0.0.1:1337".parse().unwrap();
tokio::run(lazy(move || {
tokio::runtime::run2(lazy(move |_| {
let server = Http::new().bind(&addr, || Ok(ParamExample)).unwrap();
println!("Listening on http://{} with 1 thread.", server.local_addr().unwrap());
server.run().map_err(|err| eprintln!("Server error {}", err))
println!("Listening on http://{}", server.local_addr().unwrap());
server.run().recover(|err| {
eprintln!("Server error {}", err)
})
}));
}