summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 6034e1269754ad7a90a4fedebc89f6a600217b70 (plain)
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
36
37
38
39
40
41
42
43
use tokio::signal::unix::{signal, SignalKind};
use tokio::{time::interval, time::Duration};

const ADV_INTERVAL: u64 = 3;
const SKEW_INTERVAL: u64 = 1;

async fn advert_handler() {
    println!("3 second timer fired");
}

async fn skew_handler() {
    println!("1 second timer fired");
}

async fn sighup_handler() {
    println!("got SIGHUP");
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let advert_handle = tokio::spawn(async move {
        let mut advert_interval = interval(Duration::from_secs(ADV_INTERVAL));
        loop {
            advert_interval.tick().await;
            advert_handler().await;
        }
    });
    let skew_handle = tokio::spawn(async move {
        let mut skew_interval = interval(Duration::from_secs(SKEW_INTERVAL));
        loop {
            skew_interval.tick().await;
            skew_handler().await;
        }
    });
    let sighup_handle = tokio::spawn(async move {
        let mut stream = signal(SignalKind::hangup()).expect("Should be a signal stream");
        loop {
            stream.recv().await;
            sighup_handler().await;
        }
    });
    let (_, _, _) = tokio::join!(advert_handle, skew_handle, sighup_handle);
}