From 1aba91313c721f09319653202eff4e07aadf9ab7 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 19 Mar 2019 18:18:07 -0700 Subject: [PATCH] add poll_ready to MakeConnection (#202) --- tower-service-util/src/make_connection.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tower-service-util/src/make_connection.rs b/tower-service-util/src/make_connection.rs index 976c1cf..226079f 100644 --- a/tower-service-util/src/make_connection.rs +++ b/tower-service-util/src/make_connection.rs @@ -1,5 +1,5 @@ use crate::sealed::Sealed; -use futures::Future; +use futures::{Future, Poll}; use tokio_io::{AsyncRead, AsyncWrite}; use tower_service::Service; @@ -10,13 +10,16 @@ use tower_service::Service; /// based connection or using some other method to authenticate the connection. pub trait MakeConnection: Sealed<(Request,)> { /// The transport provided by this service - type Response: AsyncRead + AsyncWrite; + type Connection: AsyncRead + AsyncWrite; /// Errors produced by the connecting service type Error; /// The future that eventually produces the transport - type Future: Future; + type Future: Future; + + /// Returns `Ready` when it is able to make more connections. + fn poll_ready(&mut self) -> Poll<(), Self::Error>; /// Connect and return a transport asynchronously fn make_connection(&mut self, target: Request) -> Self::Future; @@ -29,10 +32,14 @@ where C: Service, C::Response: AsyncRead + AsyncWrite, { - type Response = C::Response; + type Connection = C::Response; type Error = C::Error; 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 { Service::call(self, target) }