Spawn a thread to periodically get SpaceAPI's status string

This commit is contained in:
George Kaklamanos 2023-05-23 19:10:31 +03:00
parent 5452a7e06f
commit 42bdc0361d

View file

@ -14,6 +14,19 @@ struct Cli {
delay: u64,
}
use std::sync::{Arc, Mutex};
type Body = Arc<Mutex<String>>;
fn main() {
let cli = Cli::parse();
let body: Body = Arc::new(Mutex::new(String::new()));
std::thread::spawn(move || loop {
let str = client::get_prometheus_string(cli.url.clone());
let mut lock = body.lock().unwrap();
*lock = str;
drop(lock);
std::thread::sleep(std::time::Duration::from_millis(cli.delay * 1000));
});
}