rsiot/components/cmp_create_if_not_exist/
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 std::time::Duration;

use tokio::time::sleep;

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

use super::Config;

pub async fn fn_process<TMsg, TService>(
    config: Config<TMsg>,
    msg_bus: CmpInOut<TMsg, TService>,
) -> super::Result<()>
where
    TMsg: MsgDataBound,
    TService: ServiceBound,
{
    sleep(config.delay).await;

    let mut msgs = vec![];

    let cache = msg_bus.cache.read().await;
    for msg in config.msgs {
        if cache.contains_key(&msg.key) {
            continue;
        }
        msgs.push(msg);
    }
    drop(cache);

    sleep(Duration::MAX).await;
    Ok(())
}