use std::sync::OnceLock;
use tokio::runtime::Runtime;
use crate::types::VelesError;
pub(crate) fn stream_runtime() -> Result<&'static Runtime, VelesError> {
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
if let Some(rt) = RUNTIME.get() {
return Ok(rt);
}
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_name("velesdb-stream")
.build()
.map_err(|e| VelesError::Database {
message: format!("failed to start streaming runtime: {e}"),
})?;
let _ = RUNTIME.set(rt);
RUNTIME.get().ok_or_else(|| VelesError::Database {
message: "streaming runtime unavailable".to_string(),
})
}