feat(rt): make tokio runtime optional
A Cargo feature `runtime` is added, which is enabled by default, that includes the following: - The `client::HttpConnector`, which uses `tokio::net::TcpStream`. - The `server::AddrStream`, which uses `tokio::net::TcpListener`. - The `hyper::rt` module, which includes useful utilities to work with the runtime without needing to import `futures` or `tokio` explicity. Disabling the feature removes many of these niceties, but allows people to use hyper in environments that have an alternative runtime, without needing to download an unused one.
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
#![deny(warnings)]
|
||||
extern crate hyper;
|
||||
extern crate futures;
|
||||
extern crate pretty_env_logger;
|
||||
extern crate tokio;
|
||||
|
||||
use futures::{Future};
|
||||
use futures::future::{lazy};
|
||||
|
||||
use hyper::{Body, Response, Server};
|
||||
use hyper::service::service_fn_ok;
|
||||
use hyper::rt::{self, Future};
|
||||
|
||||
static INDEX1: &'static [u8] = b"The 1st service!";
|
||||
static INDEX2: &'static [u8] = b"The 2nd service!";
|
||||
@@ -19,7 +15,7 @@ fn main() {
|
||||
let addr1 = ([127, 0, 0, 1], 1337).into();
|
||||
let addr2 = ([127, 0, 0, 1], 1338).into();
|
||||
|
||||
tokio::run(lazy(move || {
|
||||
rt::run(rt::lazy(move || {
|
||||
let srv1 = Server::bind(&addr1)
|
||||
.serve(|| service_fn_ok(|_| Response::new(Body::from(INDEX1))))
|
||||
.map_err(|e| eprintln!("server 1 error: {}", e));
|
||||
@@ -30,8 +26,8 @@ fn main() {
|
||||
|
||||
println!("Listening on http://{} and http://{}", addr1, addr2);
|
||||
|
||||
tokio::spawn(srv1);
|
||||
tokio::spawn(srv2);
|
||||
rt::spawn(srv1);
|
||||
rt::spawn(srv2);
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user