Trait lifeline::prelude::CarryFrom [−][src]
Carries messages between two bus instances. A variant of the Service.
Bus types form a tree, with a 'root application' bus, and multiple busses focused on particular domains. This structure provides isolation, and predictable failures when Services spawn.
- MainBus
| ListenerBus
| | ConnectionBus
| DomainSpecificBus
| | ...
This trait can be implemented to carry messages between the root and the leaf of the tree.
Example
use lifeline::prelude::*; use tokio::sync::mpsc; lifeline_bus!(pub struct MainBus); lifeline_bus!(pub struct LeafBus); #[derive(Debug, Clone)] struct LeafShutdown {} #[derive(Debug, Clone)] struct MainShutdown {} impl Message<LeafBus> for LeafShutdown { type Channel = mpsc::Sender<Self>; } impl Message<MainBus> for MainShutdown { type Channel = mpsc::Sender<Self>; } pub struct LeafMainCarrier { _forward_shutdown: Lifeline } impl CarryFrom<MainBus> for LeafBus { type Lifeline = anyhow::Result<LeafMainCarrier>; fn carry_from(&self, from: &MainBus) -> Self::Lifeline { let mut rx = self.rx::<LeafShutdown>()?; let mut tx = from.tx::<MainShutdown>()?; let _forward_shutdown = Self::try_task("forward_shutdown", async move { if let Some(msg) = rx.recv().await { tx.send(MainShutdown{}).await?; } Ok(()) }); Ok(LeafMainCarrier { _forward_shutdown }) } }
Associated Types
Loading content...Required methods
fn carry_from(&self, from: &FromBus) -> Self::Lifeline
[src]
Spawns the carrier service, returning the lifeline value.