use std::future::Future;
use std::sync::OnceLock;
use tokio::runtime::Runtime;
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
fn runtime() -> &'static Runtime {
RUNTIME.get_or_init(|| Runtime::new().expect("failed to create tokio runtime"))
}
pub fn block_on<F: Future>(f: F) -> F::Output {
match tokio::runtime::Handle::try_current() {
Ok(_handle) => {
tokio::task::block_in_place(|| runtime().block_on(f))
}
Err(_) => runtime().block_on(f),
}
}