rsiot/components/cmp_add_output_stream/
component.rs1use async_trait::async_trait;
2
3use crate::{
4 executor::{MsgBusLinker, Component, ComponentError, IComponentProcess},
5 message::*,
6};
7
8use super::{Config, Error};
9
10pub const CMP_NAME: &str = "cmp_add_output_stream";
12
13#[cfg_attr(not(feature = "single-thread"), async_trait)]
14#[cfg_attr(feature = "single-thread", async_trait(?Send))]
15impl<TMsg> IComponentProcess<Config<TMsg>, TMsg> for Component<Config<TMsg>, TMsg>
16where
17 TMsg: MsgDataBound + 'static,
18{
19 async fn process(
20 &self,
21 config: Config<TMsg>,
22 msg_bus: MsgBusLinker<TMsg>,
23 ) -> Result<(), ComponentError> {
24 let mut input = msg_bus.init(CMP_NAME).input();
25
26 while let Ok(msg) = input.recv().await {
27 config
28 .channel
29 .send(msg.clone())
30 .await
31 .map_err(|_| Error::TokioSyncMpscSend)?;
32 }
33 Ok(())
34 }
35}
36
37pub type Cmp<TMsg> = Component<Config<TMsg>, TMsg>;