use std::sync::OnceLock;
static RT: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
pub fn runtime() -> &'static tokio::runtime::Runtime {
RT.get_or_init(|| {
tokio::runtime::Builder::new_multi_thread()
.worker_threads(2)
.thread_name("vector-net")
.enable_all()
.build()
.expect("the transport runtime must start")
})
}
pub fn spawn_on<F>(fut: F) -> tokio::task::JoinHandle<F::Output>
where
F: std::future::Future + Send + 'static,
F::Output: Send + 'static,
{
runtime().spawn(fut)
}
pub(crate) fn built() -> Option<&'static tokio::runtime::Runtime> {
RT.get()
}