use std::future::Future;
#[cfg(test)]
use std::pin::Pin;
#[cfg(test)]
use std::sync::Arc;
use khive_storage::types::TextSearchHit;
use khive_storage::StorageError;
pub(crate) type TextStageResult = Result<Vec<TextSearchHit>, StorageError>;
#[cfg(test)]
pub(crate) type BoxedTextStage = Pin<Box<dyn Future<Output = TextStageResult> + Send>>;
#[cfg(test)]
pub(crate) type TextStageDouble = Arc<dyn Fn() -> BoxedTextStage + Send + Sync>;
#[cfg(test)]
tokio::task_local! {
pub(crate) static TEXT_STAGE_DOUBLE: TextStageDouble;
}
pub(crate) async fn text_stage(stage: impl Future<Output = TextStageResult>) -> TextStageResult {
crate::search_audit::record(crate::search_audit::SearchArm::Text);
#[cfg(test)]
{
if let Ok(double) = TEXT_STAGE_DOUBLE.try_with(Arc::clone) {
return double().await;
}
}
stage.await
}