pub struct Config<TMsg, TService>where
TMsg: MsgDataBound,
TService: ServiceBound,{
pub fn_process: Box<dyn Fn(CmpInOut<TMsg, TService>) -> BoxFuture<'static, CmpResult> + Send + Sync>,
}
Expand description
Настройки cmp_external_fn_process
Fields§
§fn_process: Box<dyn Fn(CmpInOut<TMsg, TService>) -> BoxFuture<'static, CmpResult> + Send + Sync>
Внешняя функция для выполнения
Выполняемую асинхронную функцию fn_external
необходимо обернуть в функцию.
§Пример
use std::time::Duration;
use futures::future::BoxFuture;
use tokio::time::sleep;
use tracing::info;
use rsiot::{
components::cmp_external_fn_process,
executor::{CmpInOut, ComponentResult},
message::{example_message::*, *},
};
fn fn_process_wrapper<TMsg>(in_out: CmpInOut<TMsg>) -> BoxFuture<'static, ComponentResult>
where
TMsg: MsgDataBound + 'static,
{
Box::pin(async { fn_process(in_out).await })
}
async fn fn_process<TMsg>(_in_out: CmpInOut<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, TService> IComponentProcess<Config<TMsg, TService>, TMsg, TService> for Component<Config<TMsg, TService>, TMsg, TService>where
TMsg: MsgDataBound,
TService: ServiceBound,
impl<TMsg, TService> IComponentProcess<Config<TMsg, TService>, TMsg, TService> for Component<Config<TMsg, TService>, TMsg, TService>where
TMsg: MsgDataBound,
TService: ServiceBound,
Auto Trait Implementations§
impl<TMsg, TService> Freeze for Config<TMsg, TService>
impl<TMsg, TService> !RefUnwindSafe for Config<TMsg, TService>
impl<TMsg, TService> Send for Config<TMsg, TService>
impl<TMsg, TService> Sync for Config<TMsg, TService>
impl<TMsg, TService> Unpin for Config<TMsg, TService>
impl<TMsg, TService> !UnwindSafe for Config<TMsg, TService>
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