From 42bdc0361d2fd76196aaae879fe6be5df6f08312 Mon Sep 17 00:00:00 2001 From: George Kaklamanos Date: Tue, 23 May 2023 19:10:31 +0300 Subject: [PATCH] Spawn a thread to periodically get SpaceAPI's status string --- src/main.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.rs b/src/main.rs index 89c3827..f1a9761 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,19 @@ struct Cli { delay: u64, } +use std::sync::{Arc, Mutex}; +type Body = Arc>; + 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)); + }); }