Skip to content

Commit cfdb07b

Browse files
committed
feat(client/dispatch): try_poll_ready() methods
this change is motivated by aiming to use interfaces like `hyper::client::conn::http2::SendRequest::try_send_request()` or `hyper::client::conn::http1::SendRequest::try_send_request()` in the context of tower middleware; the `Service<T>` trait's signature is such that the same error type be returned from `Service::poll_ready()` and `Service::call()`. this means that services that might resolve to a recovered message may call `try_poll_ready` when polling for readiness. this avoids making `TrySendError<T>` constructable externally, see hyperium#3883 as an alternate approach that was considered. Signed-off-by: katelyn martin <git@katelyn.world>
1 parent 436cadd commit cfdb07b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/client/dispatch.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,36 @@ impl<T> TrySendError<T> {
323323
}
324324
}
325325

326+
impl<B> crate::client::conn::http1::SendRequest<B> {
327+
/// Polls to determine whether this sender can be used yet for a request.
328+
///
329+
/// If the associated connection is closed, this returns a [`TrySendError<T>`].
330+
pub fn try_poll_ready(
331+
&mut self,
332+
cx: &mut Context<'_>,
333+
) -> Poll<Result<(), TrySendError<Request<B>>>> {
334+
self.poll_ready(cx).map_err(|error| TrySendError {
335+
error,
336+
message: None,
337+
})
338+
}
339+
}
340+
341+
impl<B> crate::client::conn::http2::SendRequest<B> {
342+
/// Polls to determine whether this sender can be used yet for a request.
343+
///
344+
/// If the associated connection is closed, this returns a [`TrySendError<T>`].
345+
pub fn try_poll_ready(
346+
&mut self,
347+
cx: &mut Context<'_>,
348+
) -> Poll<Result<(), TrySendError<Request<B>>>> {
349+
self.poll_ready(cx).map_err(|error| TrySendError {
350+
error,
351+
message: None,
352+
})
353+
}
354+
}
355+
326356
#[cfg(feature = "http2")]
327357
pin_project! {
328358
pub struct SendWhen<B>

0 commit comments

Comments
 (0)