#[cfg(all(
feature = "tokio-runtime",
not(target_arch = "wasm32"),
any(feature = "embeddings", feature = "static-embeddings", feature = "reranker")
))]
use once_cell::sync::OnceCell;
#[cfg(all(
feature = "tokio-runtime",
not(target_arch = "wasm32"),
any(feature = "embeddings", feature = "static-embeddings", feature = "reranker")
))]
static GLOBAL_RUNTIME: OnceCell<tokio::runtime::Runtime> = OnceCell::new();
#[cfg(all(
feature = "tokio-runtime",
not(target_arch = "wasm32"),
any(feature = "embeddings", feature = "static-embeddings", feature = "reranker")
))]
pub(crate) fn global_runtime() -> crate::Result<&'static tokio::runtime::Runtime> {
GLOBAL_RUNTIME.get_or_try_init(|| {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.map_err(|e| crate::XbergError::Plugin {
message: format!("Failed to create global Tokio runtime: {e}"),
plugin_name: "runtime".to_string(),
})
})
}