Skip to main content

linkrs_query/executor/streaming/helpers/
runtime_bridge.rs

1//! Bridge for awaiting async coordinator operations from operator threads.
2//!
3//! Operators execute on arbitrary worker threads that may or may not run
4//! inside a tokio runtime. Remote engines require the ambient runtime's
5//! reactor and timers, so blocking waits must go through the shared
6//! runtime-aware helper instead of a bare executor block-on.
7
8#[cfg(any(feature = "vector", feature = "fulltext"))]
9use linkrs_core::error::QueryError;
10
11/// Drive `future` to completion on the calling thread, mapping both the
12/// bridging failure and the operation failure into a labeled query error.
13#[cfg(any(feature = "vector", feature = "fulltext"))]
14pub(crate) fn wait<F, T, E>(label: &str, future: F) -> Result<T, QueryError>
15where
16    F: std::future::Future<Output = Result<T, E>> + Send,
17    T: Send,
18    E: Send + std::fmt::Display,
19{
20    let label = format!("{label} failed");
21    linkrs_sync::runtime::block_on_ambient(future)
22        .map_err(|error| QueryError::execution(format!("{label}: {error}")))?
23        .map_err(|error| QueryError::execution(format!("{label}: {error}")))
24}