1pub use af_core_macros::{future_boxed as boxed, future_boxed_local as boxed_local};
10pub use std::future::Future;
11pub use std::task::{Context, Poll};
12
13mod noop_waker;
14mod try_future;
15
16pub use self::try_future::*;
17
18use crate::prelude::*;
19
20pub async fn catch_unwind<F>(f: F) -> Result<F::Output, Box<dyn Any + Send>>
24where
25 F: Future + panic::UnwindSafe,
26{
27 use futures_lite::FutureExt;
28
29 f.catch_unwind().await
30}
31
32pub async fn forever<T>() -> T {
34 futures_lite::future::pending().await
35}
36
37pub fn poll<F: Future + Unpin>(f: &mut F) -> Option<F::Output> {
39 match Pin::new(f).poll(&mut noop_waker::context()) {
40 Poll::Ready(value) => Some(value),
41 _ => None,
42 }
43}
44
45pub async fn race<T>(a: impl Future<Output = T>, b: impl Future<Output = T>) -> T {
50 use futures_lite::FutureExt;
51
52 a.or(b).await
53}
54
55pub fn try_resolve<T>(f: impl Future<Output = T>) -> Option<T> {
58 pin!(f);
59 poll(&mut f)
60}