Trait service_io::interface::OutputConnector
source · [−]pub trait OutputConnector {
fn run<'async_trait>(
self: Box<Self>,
receiver: Receiver
) -> Pin<Box<dyn Future<Output = Result<(), ClosedChannel>> + Send + 'async_trait>>
where
Self: 'async_trait;
}
Expand description
Implement an output connector. An output connector is waiting asynchronously for messages comming from the services and deliver them.
If the receiver return a ClosedChannel
error, it is expected to propagate this error.
See default implementations in connectors
Do not forget to add the async_trait
crate when implement this trait
Example
use service_io::interface::{OutputConnector};
use service_io::channel::{ClosedChannel, Receiver};
use async_trait::async_trait;
struct MyOutput;
#[async_trait]
impl OutputConnector for MyOutput {
async fn run(self: Box<Self>, mut receiver: Receiver) -> Result<(), ClosedChannel> {
// Load phase
// ...
loop {
// Get the message from the service...
let message = receiver.recv().await?;
// Do whatever your output impl must do. i.e send the message by email
// ...
}
}
}