Skip to main content

Module executor

Module executor 

Source
Expand description

Исполнитель - структура для запуска компонентов

§Пример с WASM и cmp_leptos

// #[allow(dead_code)]

#[cfg(all(
    wasm32_unknown_unknown,
    feature = "cmp_leptos",
    feature = "log_webconsole"
))]
fn main() -> anyhow::Result<()> {
    use std::time::Duration;

    use any_spawner::Executor;
    use leptos::{prelude::*, task::spawn_local};
    use reactive_stores::Store;
    use tokio::task::LocalSet;

    use rsiot::{
        components::cmp_leptos,
        executor::{ComponentExecutor, ComponentExecutorConfig},
        logging::{LogConfig, LogConfigFilter},
        message::example_message::*,
    };

    #[component]
    fn App() -> impl IntoView {}

    LogConfig {
        filter: LogConfigFilter::String("info"),
    }
    .run()?;

    #[derive(Default, Clone, Store)]
    struct GlobalStore {}

    impl cmp_leptos::StoreBound for GlobalStore {}

    // cmp_leptos ------------------------------------------------------------------------------
    let config_leptos = cmp_leptos::Config {
        body_component: || view! { <App/>}.into_any(),
        input_store: GlobalStore::default(),
        output_store: GlobalStore::default(),
        fn_input: |_, _| (),
        fn_output: |_, _| (),
    };

    // config_executor -------------------------------------------------------------------------
    let config_executor = ComponentExecutorConfig {
        buffer_size: 100,
        fn_auth: |msg, _| Some(msg),
        delay_publish: Duration::from_millis(100),
        fn_tokio_metrics: |_| None,
    };

    // executor --------------------------------------------------------------------------------
    Executor::init_wasm_bindgen().expect("executor should only be initialized once");

    let context = LocalSet::new();
    context.spawn_local(async move {
        ComponentExecutor::<Custom>::new(config_executor)
            .add_cmp(cmp_leptos::Cmp::new(config_leptos))
            .wait_result()
            .await?;
        Ok(()) as anyhow::Result<()>
    });
    spawn_local(context);
    Ok(())
}

#[cfg(not(all(
    wasm32_unknown_unknown,
    feature = "cmp_leptos",
    feature = "log_webconsole"
)))]
fn main() {
    unimplemented!()
}

Structs§

Cache
Кеш сообщений
Component
Представление обобщенного компонента
ComponentExecutor
Запуск коллекции компонентов в работу
ComponentExecutorConfig
Настройка исполнителя
Instant
Монолитно увеличивающееся время
MsgBusInput
Шина MsgBus - получение входящих сообщений
MsgBusLinker
Подключение компонента к внутренней шине сообщений исполнителя
MsgBusOutput
Шина MsgBus - отправка исходящих сообщений
TokioRuntimeMetrics
Метрики tokio

Enums§

ComponentError
Ошибки исполненителя компонентов

Traits§

CheckCapacity
Проверка емкости канала
IComponentProcess
Трейт основной функции компонента

Functions§

join_set_spawn
Добавить задачу в множество задач (многопоточная версия)
join_set_spawn_blocking
Добавить блокирующую задачу в множество задач (многопоточная версия)
sleep
Waits until duration has elapsed.

Type Aliases§

CmpResult
Тип возвращаемого значения функции process компонента