rsiot/components/cmp_telegram/
fn_process.rs

1use tokio::task::JoinSet;
2
3use crate::{
4    executor::{join_set_spawn, CmpInOut},
5    message::MsgDataBound,
6};
7
8use super::{tasks, Config, TelegramBot};
9
10pub async fn fn_process<TMsg>(config: Config<TMsg>, msg_bus: CmpInOut<TMsg>) -> super::Result<()>
11where
12    TMsg: MsgDataBound + 'static,
13{
14    let bot = TelegramBot::new(config.bot_token, config.chat_id);
15
16    let mut task_set: JoinSet<super::Result<()>> = JoinSet::new();
17
18    // Обработка входящих сообщений
19    let task = tasks::Input {
20        input: msg_bus,
21        bot,
22        fn_input: config.fn_input,
23    };
24    join_set_spawn(&mut task_set, task.spawn());
25
26    while let Some(res) = task_set.join_next().await {
27        res.unwrap().unwrap();
28    }
29
30    Ok(())
31}