use std::sync::OnceLock;
pub fn get_runtime() -> &'static tokio::runtime::Runtime {
static RUNTIME: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
RUNTIME.get_or_init(|| tokio::runtime::Runtime::new().expect("Failed to initialize static tokio runtime"))
}
pub fn run_blocking<F: std::future::Future>(f: F) -> F::Output {
if let Ok(_handle) = tokio::runtime::Handle::try_current() {
tokio::task::block_in_place(move || tokio::runtime::Handle::current().block_on(f))
} else {
get_runtime().block_on(f)
}
}