Skip to content

Commit 3fb5991

Browse files
authoredFeb 17, 2023
feat(client): add is_ready() and is_closed() methods to SendRequest (#3148)
1 parent 499fe1f commit 3fb5991

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed
 

‎src/client/conn/http1.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,21 @@ impl<B> SendRequest<B> {
141141
futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await
142142
}
143143

144-
/*
145-
pub(super) async fn when_ready(self) -> crate::Result<Self> {
146-
let mut me = Some(self);
147-
future::poll_fn(move |cx| {
148-
ready!(me.as_mut().unwrap().poll_ready(cx))?;
149-
Poll::Ready(Ok(me.take().unwrap()))
150-
})
151-
.await
152-
}
153-
154-
pub(super) fn is_ready(&self) -> bool {
144+
/// Checks if the connection is currently ready to send a request.
145+
///
146+
/// # Note
147+
///
148+
/// This is mostly a hint. Due to inherent latency of networks, it is
149+
/// possible that even after checking this is ready, sending a request
150+
/// may still fail because the connection was closed in the meantime.
151+
pub fn is_ready(&self) -> bool {
155152
self.dispatch.is_ready()
156153
}
157154

158-
pub(super) fn is_closed(&self) -> bool {
155+
/// Checks if the connection side has been closed.
156+
pub fn is_closed(&self) -> bool {
159157
self.dispatch.is_closed()
160158
}
161-
*/
162159
}
163160

164161
impl<B> SendRequest<B>

‎src/client/conn/http2.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,19 @@ impl<B> SendRequest<B> {
9292
futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await
9393
}
9494

95-
/*
96-
pub(super) async fn when_ready(self) -> crate::Result<Self> {
97-
let mut me = Some(self);
98-
future::poll_fn(move |cx| {
99-
ready!(me.as_mut().unwrap().poll_ready(cx))?;
100-
Poll::Ready(Ok(me.take().unwrap()))
101-
})
102-
.await
103-
}
104-
105-
pub(super) fn is_ready(&self) -> bool {
95+
/// Checks if the connection is currently ready to send a request.
96+
///
97+
/// # Note
98+
///
99+
/// This is mostly a hint. Due to inherent latency of networks, it is
100+
/// possible that even after checking this is ready, sending a request
101+
/// may still fail because the connection was closed in the meantime.
102+
pub fn is_ready(&self) -> bool {
106103
self.dispatch.is_ready()
107104
}
108-
*/
109105

110-
pub(super) fn is_closed(&self) -> bool {
106+
/// Checks if the connection side has been closed.
107+
pub fn is_closed(&self) -> bool {
111108
self.dispatch.is_closed()
112109
}
113110
}

‎src/client/dispatch.rs

-5
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@ impl<T, U> Sender<T, U> {
5959
.map_err(|_| crate::Error::new_closed())
6060
}
6161

62-
#[cfg(test)]
6362
pub(crate) fn is_ready(&self) -> bool {
6463
self.giver.is_wanting()
6564
}
6665

67-
/*
6866
pub(crate) fn is_closed(&self) -> bool {
6967
self.giver.is_canceled()
7068
}
71-
*/
7269

7370
fn can_send(&mut self) -> bool {
7471
if self.giver.give() || !self.buffered_once {
@@ -117,11 +114,9 @@ impl<T, U> Sender<T, U> {
117114

118115
#[cfg(feature = "http2")]
119116
impl<T, U> UnboundedSender<T, U> {
120-
/*
121117
pub(crate) fn is_ready(&self) -> bool {
122118
!self.giver.is_canceled()
123119
}
124-
*/
125120

126121
pub(crate) fn is_closed(&self) -> bool {
127122
self.giver.is_canceled()

0 commit comments

Comments
 (0)
Please sign in to comment.