diff --git a/http-service-hyper/src/lib.rs b/http-service-hyper/src/lib.rs index b0a1523..9722e81 100644 --- a/http-service-hyper/src/lib.rs +++ b/http-service-hyper/src/lib.rs @@ -78,18 +78,21 @@ where } } -/// Serve the given `HttpService` at the given address, using `hyper` as backend. -pub fn serve(s: S, addr: SocketAddr) { +/// Serve the given `HttpService` at the given address, using `hyper` as backend, and return a +/// `Future` that can be `await`ed on. +pub fn serve( + s: S, + addr: SocketAddr, +) -> impl Future> { let service = WrapHttpService { service: Arc::new(s), }; - let server = hyper::Server::bind(&addr) - .serve(service) - .compat() - .map(|_| { - let res: Result<(), ()> = Ok(()); - res - }) - .compat(); + hyper::Server::bind(&addr).serve(service).compat() +} + +/// Run the given `HttpService` at the given address on the default runtime, using `hyper` as +/// backend. +pub fn run(s: S, addr: SocketAddr) { + let server = serve(s, addr).map(|_| Result::<_, ()>::Ok(())).compat(); hyper::rt::run(server); }