Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): add is_ready() and is_closed() methods to SendRequest #3148

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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