diff --git a/src/client/conn/http1.rs b/src/client/conn/http1.rs index 4b7f93a6ba..ed87a991f9 100644 --- a/src/client/conn/http1.rs +++ b/src/client/conn/http1.rs @@ -141,24 +141,21 @@ impl SendRequest { futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await } - /* - pub(super) async fn when_ready(self) -> crate::Result { - let mut me = Some(self); - future::poll_fn(move |cx| { - ready!(me.as_mut().unwrap().poll_ready(cx))?; - Poll::Ready(Ok(me.take().unwrap())) - }) - .await - } - - pub(super) fn is_ready(&self) -> bool { + /// Checks if the connection is currently ready to send a request. + /// + /// # Note + /// + /// This is mostly a hint. Due to inherent latency of networks, it is + /// possible that even after checking this is ready, sending a request + /// may still fail because the connection was closed in the meantime. + pub fn is_ready(&self) -> bool { self.dispatch.is_ready() } - pub(super) fn is_closed(&self) -> bool { + /// Checks if the connection side has been closed. + pub fn is_closed(&self) -> bool { self.dispatch.is_closed() } - */ } impl SendRequest diff --git a/src/client/conn/http2.rs b/src/client/conn/http2.rs index f54b7a90ca..c45b67dffd 100644 --- a/src/client/conn/http2.rs +++ b/src/client/conn/http2.rs @@ -92,22 +92,19 @@ impl SendRequest { futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await } - /* - pub(super) async fn when_ready(self) -> crate::Result { - let mut me = Some(self); - future::poll_fn(move |cx| { - ready!(me.as_mut().unwrap().poll_ready(cx))?; - Poll::Ready(Ok(me.take().unwrap())) - }) - .await - } - - pub(super) fn is_ready(&self) -> bool { + /// Checks if the connection is currently ready to send a request. + /// + /// # Note + /// + /// This is mostly a hint. Due to inherent latency of networks, it is + /// possible that even after checking this is ready, sending a request + /// may still fail because the connection was closed in the meantime. + pub fn is_ready(&self) -> bool { self.dispatch.is_ready() } - */ - pub(super) fn is_closed(&self) -> bool { + /// Checks if the connection side has been closed. + pub fn is_closed(&self) -> bool { self.dispatch.is_closed() } } diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 970fb243e4..3aef84012f 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -59,16 +59,13 @@ impl Sender { .map_err(|_| crate::Error::new_closed()) } - #[cfg(test)] pub(crate) fn is_ready(&self) -> bool { self.giver.is_wanting() } - /* pub(crate) fn is_closed(&self) -> bool { self.giver.is_canceled() } - */ fn can_send(&mut self) -> bool { if self.giver.give() || !self.buffered_once { @@ -117,11 +114,9 @@ impl Sender { #[cfg(feature = "http2")] impl UnboundedSender { - /* pub(crate) fn is_ready(&self) -> bool { !self.giver.is_canceled() } - */ pub(crate) fn is_closed(&self) -> bool { self.giver.is_canceled()