use std::any::Any;
use crate::runtime::chain_segment::ChainTailSegment;
use tinyflow_api::context::RuntimeContext;
use tinyflow_api::error::StreamResult;
pub(super) async fn run_through_chain(
tail_steps: &mut [Box<dyn ChainTailSegment>],
input: Box<dyn Any + Send>,
runtime: &mut RuntimeContext,
) -> StreamResult<()> {
let mut pending = vec![input];
let last = tail_steps.len().saturating_sub(1);
for (i, step) in tail_steps.iter_mut().enumerate() {
let mut next = Vec::new();
for record in pending {
next.extend(step.process_record(record, runtime).await?);
}
if next.is_empty() {
return Ok(());
}
if i == last {
return Ok(());
}
pending = next;
}
Ok(())
}