add poll_ready to MakeConnection (#202)

This commit is contained in:
Sean McArthur 2019-03-19 18:18:07 -07:00 committed by GitHub
parent 728f9d3c37
commit 1aba91313c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,5 @@
use crate::sealed::Sealed; use crate::sealed::Sealed;
use futures::Future; use futures::{Future, Poll};
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use tower_service::Service; use tower_service::Service;
@ -10,13 +10,16 @@ use tower_service::Service;
/// based connection or using some other method to authenticate the connection. /// based connection or using some other method to authenticate the connection.
pub trait MakeConnection<Request>: Sealed<(Request,)> { pub trait MakeConnection<Request>: Sealed<(Request,)> {
/// The transport provided by this service /// The transport provided by this service
type Response: AsyncRead + AsyncWrite; type Connection: AsyncRead + AsyncWrite;
/// Errors produced by the connecting service /// Errors produced by the connecting service
type Error; type Error;
/// The future that eventually produces the transport /// The future that eventually produces the transport
type Future: Future<Item = Self::Response, Error = Self::Error>; type Future: Future<Item = Self::Connection, Error = Self::Error>;
/// Returns `Ready` when it is able to make more connections.
fn poll_ready(&mut self) -> Poll<(), Self::Error>;
/// Connect and return a transport asynchronously /// Connect and return a transport asynchronously
fn make_connection(&mut self, target: Request) -> Self::Future; fn make_connection(&mut self, target: Request) -> Self::Future;
@ -29,10 +32,14 @@ where
C: Service<Request>, C: Service<Request>,
C::Response: AsyncRead + AsyncWrite, C::Response: AsyncRead + AsyncWrite,
{ {
type Response = C::Response; type Connection = C::Response;
type Error = C::Error; type Error = C::Error;
type Future = C::Future; type Future = C::Future;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Service::poll_ready(self)
}
fn make_connection(&mut self, target: Request) -> Self::Future { fn make_connection(&mut self, target: Request) -> Self::Future {
Service::call(self, target) Service::call(self, target)
} }