feat(service): add poll_ready to Service and MakeService (#1767)

This commit is contained in:
Yusuke Sasaki
2019-02-28 02:30:52 +09:00
committed by Sean McArthur
parent ce2b540f9d
commit 0bf30ccc68
6 changed files with 84 additions and 18 deletions

View File

@@ -2,7 +2,7 @@ use std::error::Error as StdError;
use std::fmt;
use std::marker::PhantomData;
use futures::{future, Future, IntoFuture};
use futures::{future, Async, Future, IntoFuture, Poll};
use body::Payload;
use common::Never;
@@ -26,6 +26,15 @@ pub trait Service {
/// The `Future` returned by this `Service`.
type Future: Future<Item=Response<Self::ResBody>, Error=Self::Error>;
/// Returns `Ready` when the service is able to process requests.
///
/// The implementation of this method is allowed to return a `Ready` even if
/// the service is not ready to process. In this case, the future returned
/// from `call` will resolve to an error.
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Ok(Async::Ready(()))
}
/// Calls this `Service` with a request, returning a `Future` of the response.
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future;
}