summaryrefslogtreecommitdiff
path: root/src/client/connector.rs
blob: 709b91d57ec0a1fa8fb2749b7c6f4b4d4d3998c0 (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
pub(crate) mod connectors;
pub(crate) mod manager;

use std::{thread::sleep, time};

pub(crate) trait Connection {
    type Err: std::fmt::Display;
    type Success: std::fmt::Display = String;

    // should use channel to notify update
    fn update(&self) -> Option<Result<Self::Success, Self::Err>>; // None if no update(content is same)

    fn r#loop(&self) -> ! {
        loop {
            // if let Some(Err(e)) = self.update() {
            //     eprintln!("Error: {}", e)
            // }
            match self.update() {
                Some(Ok(s)) => {
                    // _ = self.channel.sender.send(res.clone()); // don't care if receiver is dropped
                    // _ = executor::new(res.as_str());
                }
                Some(Err(e)) => eprintln!("Error: {}", e),
                _ => {}
            }

            sleep(time::Duration::from_secs(1));
        }
    }
}