#[cfg(feature = "http")]
pub use rok_ui_http::runtime::{block_on, get, spawn};
#[cfg(not(feature = "http"))]
use std::{future::Future, sync::OnceLock};
#[cfg(not(feature = "http"))]
pub fn get() -> &'static tokio::runtime::Runtime {
static RUNTIME: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
RUNTIME.get_or_init(|| {
tokio::runtime::Builder::new_multi_thread()
.worker_threads(2)
.thread_name("rok-ui-runtime")
.enable_all()
.build()
.expect("failed to start the rok-ui runtime")
})
}
#[cfg(not(feature = "http"))]
pub fn spawn<F>(future: F) -> tokio::task::JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
get().spawn(future)
}
#[cfg(not(feature = "http"))]
pub fn block_on<F: Future>(future: F) -> F::Output {
get().block_on(future)
}