use async_trait::async_trait;
use coreon_core::{Exchange, Processor, Result};
use std::sync::Arc;
use tracing::warn;
pub struct WireTap {
branch: Arc<dyn Processor>,
}
impl WireTap {
pub fn new(branch: Arc<dyn Processor>) -> Arc<Self> {
Arc::new(Self { branch })
}
}
#[async_trait]
impl Processor for WireTap {
async fn process(&self, exchange: &mut Exchange) -> Result<()> {
let mut copy = exchange.clone();
let branch = self.branch.clone();
tokio::spawn(async move {
if let Err(e) = branch.process(&mut copy).await {
warn!(error = %e, "wire-tap branch failed");
}
});
Ok(())
}
}