Spawn a thread to periodically get SpaceAPI's status string
This commit is contained in:
parent
5452a7e06f
commit
42bdc0361d
1 changed files with 13 additions and 0 deletions
13
src/main.rs
13
src/main.rs
|
@ -14,6 +14,19 @@ struct Cli {
|
||||||
delay: u64,
|
delay: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
type Body = Arc<Mutex<String>>;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
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));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue