rsiot/components/cmp_telegram/
fn_process.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use tokio::task::JoinSet;

use crate::{
    executor::{join_set_spawn, CmpInOut},
    message::{MsgDataBound, ServiceBound},
};

use super::{tasks, Config, TelegramBot};

pub async fn fn_process<TMsg, TService>(
    config: Config<TMsg>,
    msg_bus: CmpInOut<TMsg, TService>,
) -> super::Result<()>
where
    TMsg: MsgDataBound + 'static,
    TService: ServiceBound + 'static,
{
    let bot = TelegramBot::new(config.bot_token, config.chat_id);

    let mut task_set: JoinSet<super::Result<()>> = JoinSet::new();

    // Обработка входящих сообщений
    let task = tasks::Input {
        input: msg_bus,
        bot,
        fn_input: config.fn_input,
    };
    join_set_spawn(&mut task_set, task.spawn());

    while let Some(res) = task_set.join_next().await {
        res.unwrap().unwrap();
    }

    Ok(())
}