//! Pipeline — sequential composition of Processors.
use async_trait::async_trait;
use coreon_core::{Exchange, Processor, Result};
use std::sync::Arc;
pub struct Pipeline {
steps: Vec<Arc<dyn Processor>>,
}
impl Pipeline {
pub fn new(steps: Vec<Arc<dyn Processor>>) -> Arc<Self> {
Arc::new(Self { steps })
}
}
#[async_trait]
impl Processor for Pipeline {
async fn process(&self, exchange: &mut Exchange) -> Result<()> {
for step in &self.steps {
step.process(exchange).await?;
// Camel semantics: after each step, the step's OUT becomes the
// next step's IN. Steps that don't write OUT leave the exchange
// unchanged.
exchange.advance();
}
Ok(())
}
}