pub struct Config<TMsg> {
pub fn_process: Box<dyn Fn(CmpInOut<TMsg>) -> BoxFuture<'static, ComponentResult> + Send + Sync>,
}Fields§
§fn_process: Box<dyn Fn(CmpInOut<TMsg>) -> BoxFuture<'static, ComponentResult> + Send + Sync>Внешняя функция для выполнения
Выполняемую асинхронную функцию fn_external необходимо обернуть в функцию.
use std::time::Duration;
use futures::future::BoxFuture;
use tokio::time::sleep;
use tracing::info;
use rsiot_component_core::{Cache, CmpInput, CmpOutput, ComponentResult};
use rsiot_messages_core::{example_message::*, *};
fn fn_process_wrapper<TMsg>(
input: CmpInput<TMsg>,
output: CmpOutput<TMsg>,
cache: Cache<TMsg>,
) -> BoxFuture<'static, ComponentResult>
where
TMsg: MsgDataBound + 'static,
{
Box::pin(async { fn_process(input, output, cache).await })
}
async fn fn_process<TMsg>(
_input: CmpInput<TMsg>,
_output: CmpOutput<TMsg>,
_cache: Cache<TMsg>,
) -> ComponentResult {
loop {
info!("External fn process");
sleep(Duration::from_secs(2)).await;
}
}
let _config = cmp_external_fn_process::Config {
fn_process: Box::new(fn_process_wrapper::<Custom>),
};Trait Implementations§
Source§impl<TMsg> IComponentProcess<Config<TMsg>, TMsg> for Component<Config<TMsg>, TMsg>where
TMsg: MsgDataBound,
impl<TMsg> IComponentProcess<Config<TMsg>, TMsg> for Component<Config<TMsg>, TMsg>where
TMsg: MsgDataBound,
Auto Trait Implementations§
impl<TMsg> Freeze for Config<TMsg>
impl<TMsg> !RefUnwindSafe for Config<TMsg>
impl<TMsg> Send for Config<TMsg>
impl<TMsg> Sync for Config<TMsg>
impl<TMsg> Unpin for Config<TMsg>
impl<TMsg> !UnwindSafe for Config<TMsg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more