1use once_cell::sync::Lazy;
2use tokio::runtime::{self, Handle};
3
4static RUNTIME: Lazy<runtime::Runtime> = Lazy::new(|| {
5 runtime::Builder::new_multi_thread()
6 .enable_all()
7 .thread_name("greentic-secrets-rt")
8 .build()
9 .expect("build greentic-secrets runtime")
10});
11
12pub fn sync_await<F>(fut: F) -> F::Output
14where
15 F: std::future::Future,
16{
17 if let Ok(handle) = Handle::try_current() {
18 tokio::task::block_in_place(|| handle.block_on(fut))
19 } else {
20 RUNTIME.block_on(fut)
21 }
22}