#![cfg_attr(
not(any(feature = "tokio", feature = "async-stds", feature = "futures-lite")),
no_std
)]
use core::task::{Context, Poll};
#[allow(unreachable_code)]
pub async fn yield_now() {
#[cfg(feature = "tokio")]
if tokio::runtime::Handle::try_current().is_ok() {
return tokio::task::yield_now().await;
}
#[cfg(feature = "async-std")]
return async_std::task::yield_now().await;
#[cfg(feature = "futures-lite")]
return futures_lite::future::yield_now().await;
YieldNow::Yield.await
}
#[derive(Clone, Copy, Debug)]
pub enum YieldNow {
Yield,
Ready,
}
impl core::future::Future for YieldNow {
type Output = ();
fn poll(mut self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match *self {
Self::Yield => {
*self = Self::Ready;
cx.waker().wake_by_ref();
Poll::Pending
}
Self::Ready => Poll::Ready(()),
}
}
}