1 | use std::future::Future; |
2 | use std::marker::PhantomData; |
3 | use std::pin::Pin; |
4 | |
5 | use crate::task::{Context, Poll}; |
6 | |
7 | /// Never resolves to a value. |
8 | /// |
9 | /// # Examples |
10 | /// |
11 | /// ``` |
12 | /// # async_std::task::block_on(async { |
13 | /// # |
14 | /// use std::time::Duration; |
15 | /// |
16 | /// use async_std::future; |
17 | /// use async_std::io; |
18 | /// |
19 | /// let dur = Duration::from_secs(1); |
20 | /// let fut = future::pending(); |
21 | /// |
22 | /// let res: io::Result<()> = io::timeout(dur, fut).await; |
23 | /// assert!(res.is_err()); |
24 | /// # |
25 | /// # }) |
26 | /// ``` |
27 | pub async fn pending<T>() -> T { |
28 | let fut: Pending = Pending { |
29 | _marker: PhantomData, |
30 | }; |
31 | fut.await |
32 | } |
33 | |
34 | struct Pending<T> { |
35 | _marker: PhantomData<T>, |
36 | } |
37 | |
38 | impl<T> Future for Pending<T> { |
39 | type Output = T; |
40 | |
41 | fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> { |
42 | Poll::Pending |
43 | } |
44 | } |
45 | |