starfish_common/
runtime.rs1use std::future::Future;
2use tokio::runtime::{Builder, Handle, Runtime};
3
4static mut INS: Option<Runtime> = None;
5
6pub fn init() {
7 let rt: Runtime = Builder::new_multi_thread()
8 .thread_name("Starfish")
9 .enable_all()
10 .build()
11 .unwrap();
12 unsafe { INS = Some(rt) }
13}
14
15pub fn get() -> &'static Runtime {
16 unsafe { INS.as_ref().unwrap() }
17}
18
19pub fn blocking<F: Future>(future: F) -> F::Output {
20 tokio::task::block_in_place(move || Handle::current().block_on(future))
21}