wreq_util/tower/delay/
future.rs

1use std::{
2    pin::Pin,
3    task::{Context, Poll, ready},
4};
5
6use pin_project_lite::pin_project;
7use tokio::time::Sleep;
8use tower::BoxError;
9
10pin_project! {
11    /// Response future for [`Delay`].
12    ///
13    /// [`Delay`]: super::Delay
14    #[derive(Debug)]
15    pub struct ResponseFuture<S> {
16        #[pin]
17        response: S,
18        #[pin]
19        sleep: Sleep,
20    }
21}
22
23impl<S> ResponseFuture<S> {
24    // Create a new [`ResponseFuture`]
25    #[inline]
26    pub(crate) fn new(response: S, sleep: Sleep) -> Self {
27        ResponseFuture { response, sleep }
28    }
29}
30
31impl<F, S, E> Future for ResponseFuture<F>
32where
33    F: Future<Output = Result<S, E>>,
34    E: Into<BoxError>,
35{
36    type Output = Result<S, BoxError>;
37
38    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
39        let this = self.project();
40        ready!(this.sleep.poll(cx));
41        this.response.poll(cx).map_err(Into::into)
42    }
43}