dd: Simplify loop of progress Alarm thread

This commit is contained in:
Thomas Hurst 2023-03-01 13:56:18 +00:00
parent cf7b90bbe7
commit 52c93a4d10

View file

@ -80,20 +80,18 @@ pub struct Alarm {
}
impl Alarm {
pub fn with_interval(interval: Duration) -> Alarm {
pub fn with_interval(interval: Duration) -> Self {
let trigger = Arc::new(AtomicBool::default());
let weak_trigger = Arc::downgrade(&trigger);
std::thread::spawn(move || loop {
sleep(interval);
if let Some(trigger) = weak_trigger.upgrade() {
std::thread::spawn(move || {
while let Some(trigger) = weak_trigger.upgrade() {
sleep(interval);
trigger.store(true, Relaxed);
} else {
break;
}
});
Alarm { interval, trigger }
Self { interval, trigger }
}
pub fn is_triggered(&self) -> bool {