rsiot/components/cmp_add_output_stream/
mod.rs1use async_trait::async_trait;
4use tokio::sync::mpsc;
5
6use crate::{
7 executor::{CmpInOut, Component, ComponentError, IComponentProcess},
8 message::*,
9};
10
11#[derive(Debug)]
13pub struct Config<TMessage> {
14 pub channel: mpsc::Sender<Message<TMessage>>,
16}
17
18#[cfg_attr(not(feature = "single-thread"), async_trait)]
19#[cfg_attr(feature = "single-thread", async_trait(?Send))]
20impl<TMsg> IComponentProcess<Config<TMsg>, TMsg> for Component<Config<TMsg>, TMsg>
21where
22 TMsg: MsgDataBound + 'static,
23{
24 async fn process(
25 &self,
26 config: Config<TMsg>,
27 in_out: CmpInOut<TMsg>,
28 ) -> Result<(), ComponentError> {
29 let mut in_out =
30 in_out.clone_with_new_id("cmp_add_output_stream", AuthPermissions::FullAccess);
31 while let Ok(msg) = in_out.recv_input().await {
32 config.channel.send(msg.clone()).await.unwrap();
33 }
34 Ok(())
35 }
36}
37
38pub type Cmp<TMsg> = Component<Config<TMsg>, TMsg>;