/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tower-0.5.3/src/timeout/future.rs
Line | Count | Source |
1 | | //! Future types |
2 | | |
3 | | use super::error::Elapsed; |
4 | | use pin_project_lite::pin_project; |
5 | | use std::{ |
6 | | future::Future, |
7 | | pin::Pin, |
8 | | task::{Context, Poll}, |
9 | | }; |
10 | | use tokio::time::Sleep; |
11 | | |
12 | | pin_project! { |
13 | | /// [`Timeout`] response future |
14 | | /// |
15 | | /// [`Timeout`]: crate::timeout::Timeout |
16 | | #[derive(Debug)] |
17 | | pub struct ResponseFuture<T> { |
18 | | #[pin] |
19 | | response: T, |
20 | | #[pin] |
21 | | sleep: Sleep, |
22 | | } |
23 | | } |
24 | | |
25 | | impl<T> ResponseFuture<T> { |
26 | 0 | pub(crate) fn new(response: T, sleep: Sleep) -> Self { |
27 | 0 | ResponseFuture { response, sleep } |
28 | 0 | } Unexecuted instantiation: <tower::timeout::future::ResponseFuture<core::pin::Pin<alloc::boxed::Box<dyn core::future::future::Future<Output = core::result::Result<reqwest::connect::sealed::Conn, alloc::boxed::Box<dyn core::error::Error + core::marker::Sync + core::marker::Send>>> + core::marker::Send>>>>::new Unexecuted instantiation: <tower::timeout::future::ResponseFuture<_>>::new |
29 | | } |
30 | | |
31 | | impl<F, T, E> Future for ResponseFuture<F> |
32 | | where |
33 | | F: Future<Output = Result<T, E>>, |
34 | | E: Into<crate::BoxError>, |
35 | | { |
36 | | type Output = Result<T, crate::BoxError>; |
37 | | |
38 | 0 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
39 | 0 | let this = self.project(); |
40 | | |
41 | | // First, try polling the future |
42 | 0 | match this.response.poll(cx) { |
43 | 0 | Poll::Ready(v) => return Poll::Ready(v.map_err(Into::into)), |
44 | 0 | Poll::Pending => {} |
45 | | } |
46 | | |
47 | | // Now check the sleep |
48 | 0 | match this.sleep.poll(cx) { |
49 | 0 | Poll::Pending => Poll::Pending, |
50 | 0 | Poll::Ready(_) => Poll::Ready(Err(Elapsed(()).into())), |
51 | | } |
52 | 0 | } Unexecuted instantiation: <tower::timeout::future::ResponseFuture<core::pin::Pin<alloc::boxed::Box<dyn core::future::future::Future<Output = core::result::Result<reqwest::connect::sealed::Conn, alloc::boxed::Box<dyn core::error::Error + core::marker::Sync + core::marker::Send>>> + core::marker::Send>>> as core::future::future::Future>::poll Unexecuted instantiation: <tower::timeout::future::ResponseFuture<_> as core::future::future::Future>::poll |
53 | | } |