use std::{
io::stdin,
sync::{atomic::AtomicBool, Arc, Mutex},
time::Duration,
};
use utls::watcher::Watcher;
fn main() {
let sd = Arc::new(Mutex::new(AtomicBool::new(false)));
let watcher = Watcher::with_lifetime(
9,
1,
sd,
Duration::from_secs(5),
utls::expiration::ExpirationAction::RunFunc(|a| println!("{}", a.0), ("hello", "")),
);
loop {
let mut input = String::new();
stdin().read_line(&mut input).unwrap();
if input.trim() == "add" {
let current = watcher.get_value();
watcher.set_value(current + 1);
println!("Value is now: {}", watcher.get_value());
}
if watcher.has_changed() {
println!("Value was changed!");
break;
}
if watcher.is_expired() {
println!("Operation timed out.");
break;
}
}
println!("broke loop");
drop(watcher)
}