diff --git a/src/client.rs b/src/client.rs index e3485da..286346d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -28,6 +28,13 @@ pub struct SendRequest { pending: Option, } +/// Returns a `SendRequest` instance once it is ready to send at least one +/// request. +#[derive(Debug)] +pub struct ReadySendRequest { + inner: Option>, +} + /// A future to drive the H2 protocol on a connection. /// /// This must be placed in an executor to ensure proper connection management. @@ -78,6 +85,12 @@ where Ok(().into()) } + /// Consumes `self`, returning a future that returns `self` back once it is + /// ready to send a request. + pub fn ready(self) -> ReadySendRequest { + ReadySendRequest { inner: Some(self) } + } + /// Send a request on a new HTTP 2.0 stream pub fn send_request( &mut self, @@ -147,6 +160,27 @@ where } } +// ===== impl ReadySendRequest ===== + +impl Future for ReadySendRequest +where B: IntoBuf, + B::Buf: 'static, +{ + type Item = SendRequest; + type Error = ::Error; + + fn poll(&mut self) -> Poll { + match self.inner { + Some(ref mut send_request) => { + let _ = try_ready!(send_request.poll_ready()); + } + None => panic!("called `poll` after future completed"), + } + + Ok(self.inner.take().unwrap().into()) + } +} + // ===== impl Builder ===== impl Builder {