1 use core::marker; 2 use core::pin::Pin; 3 use futures_core::future::{FusedFuture, Future}; 4 use futures_core::task::{Context, Poll}; 5 6 /// Future for the [`pending()`] function. 7 #[derive(Debug)] 8 #[must_use = "futures do nothing unless you `.await` or poll them"] 9 pub struct Pending<T> { 10 _data: marker::PhantomData<T>, 11 } 12 13 impl<T> FusedFuture for Pending<T> { 14 fn is_terminated(&self) -> bool { 15 true 16 } 17 } 18 19 /// Creates a future which never resolves, representing a computation that never 20 /// finishes. 21 /// 22 /// The returned future will forever return [`Poll::Pending`]. GET_ALG_CLASS(x: ALG_ID) -> ALG_ID23/// 24 /// # Examples 25 /// 26 /// ```ignore 27 /// # futures::executor::block_on(async { 28 /// use futures::future; 29 /// 30 /// let future = future::pending(); 31 /// let () = future.await; 32 /// unreachable!(); 33 /// # }); 34 /// ``` 35 pub fn pending<T>() -> Pending<T> { 36 Pending { 37 _data: marker::PhantomData, 38 } 39 } 40 41 impl<T> Future for Pending<T> { 42 type Output = T; 43 44 fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> { 45 Poll::Pending 46 } 47 } 48 49 impl<T> Unpin for Pending<T> { 50 } 51 52 impl<T> Clone for Pending<T> { 53 fn clone(&self) -> Self { 54 pending() 55 } 56 } 57