use async_trait::async_trait;
use coreon_core::{CamelContext, Exchange, Processor, Result};
use std::sync::{Arc, Weak};
pub struct To {
uri: String,
ctx: Weak<CamelContext>,
}
impl To {
pub fn new(uri: impl Into<String>, ctx: &Arc<CamelContext>) -> Arc<Self> {
Arc::new(Self {
uri: uri.into(),
ctx: Arc::downgrade(ctx),
})
}
}
#[async_trait]
impl Processor for To {
async fn process(&self, exchange: &mut Exchange) -> Result<()> {
let ctx = self
.ctx
.upgrade()
.ok_or_else(|| coreon_core::CamelError::NotRunning)?;
ctx.send(&self.uri, exchange).await
}
}