Skip to content

Commit

Permalink
feat(client): add is_ready() and is_closed() methods to `SendRequ…
Browse files Browse the repository at this point in the history
…est` (#3148)
  • Loading branch information
seanmonstar committed Feb 17, 2023
1 parent 499fe1f commit 3fb5991
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
23 changes: 10 additions & 13 deletions src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,21 @@ impl<B> SendRequest<B> {
futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await
}

/*
pub(super) async fn when_ready(self) -> crate::Result<Self> {
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<B> SendRequest<B>
Expand Down
23 changes: 10 additions & 13 deletions src/client/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,19 @@ impl<B> SendRequest<B> {
futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await
}

/*
pub(super) async fn when_ready(self) -> crate::Result<Self> {
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()
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,13 @@ impl<T, U> Sender<T, U> {
.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 {
Expand Down Expand Up @@ -117,11 +114,9 @@ impl<T, U> Sender<T, U> {

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

pub(crate) fn is_closed(&self) -> bool {
self.giver.is_canceled()
Expand Down

0 comments on commit 3fb5991

Please sign in to comment.