macro_rules! select_runtime {
(tokio: $tokio:expr, async_io: $async_io:expr $(,)?) => {{
#[cfg(all(feature = "tokio", feature = "async-io"))]
{
if $crate::abstractions::use_tokio() {
$tokio
} else {
$async_io
}
}
#[cfg(all(feature = "tokio", not(feature = "async-io")))]
{
$tokio
}
#[cfg(all(feature = "async-io", not(feature = "tokio")))]
{
$async_io
}
}};
}
pub(crate) use select_runtime;
#[cfg(feature = "async-io")]
pub(crate) fn use_tokio() -> bool {
#[cfg(feature = "tokio")]
{
tokio::runtime::Handle::try_current().is_ok()
}
#[cfg(not(feature = "tokio"))]
{
false
}
}
mod executor;
pub use executor::*;
mod async_drop;
pub(crate) mod async_lock;
pub use async_drop::*;
pub(crate) mod timeout;
#[cfg(target_family = "unix")]
pub(crate) mod process;
#[cfg(all(test, feature = "tokio", feature = "async-io"))]
mod tests {
#[test]
fn use_tokio_reflects_active_runtime() {
assert!(!super::use_tokio(), "no runtime is active here");
let runtime = tokio::runtime::Runtime::new().unwrap();
assert!(
runtime.block_on(async { super::use_tokio() }),
"a tokio runtime is active",
);
}
}