use std::{future::Future, io};
use tokio::runtime::Handle;
pub fn inside_tokio() -> bool {
Handle::try_current().is_ok()
}
pub fn block_on_tokio<T>(fut: impl Future<Output = io::Result<T>>) -> io::Result<T> {
if let Ok(handle) = Handle::try_current() {
handle.block_on(fut)
} else {
tokio::runtime::Runtime::new()?.block_on(fut)
}
}