Skip to main content

rsiot/components/cmp_http_client_wasm/
component.rs

1//! Компонент HTTP-клиент для платформы wasm
2
3use async_trait::async_trait;
4
5use crate::{
6    executor::{Component, ComponentError, IComponentProcess, MsgBusLinker},
7    message::MsgDataBound,
8};
9
10use super::{config::Config, fn_process::fn_process};
11
12/// Название компонента
13pub const COMPONENT_NAME: &str = "cmp_http_client_wasm";
14
15#[allow(unreachable_code)]
16#[cfg(not(feature = "single-thread"))]
17#[async_trait]
18impl<TMsg> IComponentProcess<Config<TMsg>, TMsg> for Component<Config<TMsg>, TMsg>
19where
20    TMsg: MsgDataBound + 'static,
21{
22    async fn process(
23        &self,
24        _config: ConfigAlias<TMsg>,
25        _input: MsgBusLinker<TMsg>,
26    ) -> Result<(), ComponentError> {
27        unimplemented!();
28        let config = _config.0;
29        fn_process(_input, config)
30            .await
31            .map_err(|err| ComponentError::Execution(err.to_string()))
32    }
33}
34
35#[cfg(feature = "single-thread")]
36#[async_trait(?Send)]
37impl<TMsg> IComponentProcess<Config<TMsg>, TMsg> for Component<Config<TMsg>, TMsg>
38where
39    TMsg: MsgDataBound + 'static,
40{
41    async fn process(
42        &self,
43        config: Config<TMsg>,
44        msgbus_linker: MsgBusLinker<TMsg>,
45    ) -> Result<(), ComponentError> {
46        fn_process(msgbus_linker.init(COMPONENT_NAME), config)
47            .await
48            .map_err(|err| ComponentError::Execution(err.to_string()))
49    }
50}
51
52/// Компонент cmp_http_client_wasm
53pub type Cmp<TMsg> = Component<Config<TMsg>, TMsg>;