pub use af_core_macros::{future_boxed as boxed, future_boxed_local as boxed_local};
pub use std::future::Future;
pub use std::task::{Context, Poll};
mod noop_waker;
mod try_future;
pub use self::try_future::*;
use crate::prelude::*;
pub async fn catch_unwind<F>(f: F) -> Result<F::Output, Box<dyn Any + Send>>
where
F: Future + panic::UnwindSafe,
{
use futures_lite::FutureExt;
f.catch_unwind().await
}
pub async fn forever<T>() -> T {
futures_lite::future::pending().await
}
pub fn poll<F: Future + Unpin>(f: &mut F) -> Option<F::Output> {
match Pin::new(f).poll(&mut noop_waker::context()) {
Poll::Ready(value) => Some(value),
_ => None,
}
}
pub async fn race<T>(a: impl Future<Output = T>, b: impl Future<Output = T>) -> T {
use futures_lite::FutureExt;
a.or(b).await
}
pub fn try_resolve<T>(f: impl Future<Output = T>) -> Option<T> {
pin!(f);
poll(&mut f)
}