summaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 28eb8dc2b0439cec96f6282d13a0e14970be61c5 (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
44
45
46
47
mod enums;
mod events;
mod commands;
mod client;

use std::error::Error;
use std::time::Duration;
use std::sync::Arc;

use tokio::sync::Mutex;

use client::*;
use commands::Command;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {

    let event = event_handler(|event| { println!("ping response: {:?}", event); });
    let event2 = event_handler(|event| { println!("ping response: {:?}", event); });

    let client = FlicClient::new("127.0.0.1:5551").await?
        .register_event_handler(event).await
        .register_event_handler(event2).await
    ;
    let client1 = Arc::new(client);
    let client2 = client1.clone();

    let cmd = tokio::spawn(async move {
        client1.submit(Command::GetInfo).await;
        tokio::time::delay_for(Duration::from_secs(3)).await;
        client1.submit(Command::GetInfo).await;
        tokio::time::delay_for(Duration::from_secs(3)).await;
        client1.stop().await;
    });
    let lst = tokio::spawn(async move {
        while client2.is_running().await {
            client2.listen().await;
        }
        println!("stop");
    });

    lst.await;
    cmd.await;

    Ok(())
}