hiro_system_kit/
tokio_helpers.rs

1use std::future::Future;
2
3pub fn create_basic_runtime() -> tokio::runtime::Runtime {
4    tokio::runtime::Builder::new_current_thread()
5        .enable_io()
6        .enable_time()
7        .max_blocking_threads(32)
8        .build()
9        .unwrap()
10}
11
12pub fn nestable_block_on<F: Future>(future: F) -> F::Output {
13    let (handle, _rt) = match tokio::runtime::Handle::try_current() {
14        Ok(h) => (h, None),
15        Err(_) => {
16            let rt = tokio::runtime::Runtime::new().unwrap();
17            (rt.handle().clone(), Some(rt))
18        }
19    };
20    handle.block_on(future)
21}
22
23// pub fn spawn_async_thread_named<F: Future>(name: &str, f: F) -> io::Result<JoinHandle<F::Output>> {
24//     thread_named(name).spawn(move || {
25//         nestable_block_on(f)
26//     })
27// }