1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use crate::DelayShutdownToken;
pub struct WrapWait<F> {
pub(crate) delay_token: Option<DelayShutdownToken>,
pub(crate) future: F,
}
impl<F: Future> Future for WrapWait<F> {
type Output = F::Output;
#[inline]
fn poll(self: Pin<&mut Self>, context: &mut Context) -> Poll<Self::Output> {
unsafe {
let me = self.get_unchecked_mut();
match Pin::new_unchecked(&mut me.future).poll(context) {
Poll::Pending => Poll::Pending,
Poll::Ready(value) => {
me.delay_token = None;
Poll::Ready(value)
},
}
}
}
}