rsiot/components/cmp_inject_periodic/
component.rs1use async_trait::async_trait;
2
3use crate::{
4 executor::{Component, ComponentError, IComponentProcess, MsgBusLinker},
5 message::MsgDataBound,
6};
7
8use super::{config::Config, fn_process::fn_process};
9
10pub const COMPONENT_NAME: &str = "cmp_inject_periodic";
12
13#[cfg_attr(not(feature = "single-thread"), async_trait)]
14#[cfg_attr(feature = "single-thread", async_trait(?Send))]
15impl<TMsg, TFnPeriodic> IComponentProcess<Config<TMsg, TFnPeriodic>, TMsg>
16 for Component<Config<TMsg, TFnPeriodic>, TMsg>
17where
18 TMsg: 'static + MsgDataBound,
19 TFnPeriodic: 'static + FnMut() -> Vec<TMsg> + Send + Sync,
20{
21 async fn process(
22 &self,
23 config: Config<TMsg, TFnPeriodic>,
24 msg_bus: MsgBusLinker<TMsg>,
25 ) -> Result<(), ComponentError> {
26 let msg_bus = msg_bus.init(COMPONENT_NAME);
27 fn_process(config, msg_bus).await?;
28 Ok(())
29 }
30}
31
32pub type Cmp<TMsg, TFnPeriodic> = Component<Config<TMsg, TFnPeriodic>, TMsg>;