use crate::Moirai;
use moirai_core::task::TaskHandle;
use std::future::Future;
static GLOBAL_RUNTIME: std::sync::OnceLock<Moirai> = std::sync::OnceLock::new();
pub fn global() -> &'static Moirai {
GLOBAL_RUNTIME.get_or_init(|| Moirai {
executor: moirai_executor::shared(),
})
}
pub fn spawn_async<F>(future: F) -> TaskHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
global().spawn_async(future)
}
pub fn spawn_fn<F, R>(func: F) -> TaskHandle<R>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
global().spawn_fn(func)
}
pub fn block_on<F>(future: F) -> F::Output
where
F: Future,
{
global().block_on(future)
}