Skip to content

Commit

Permalink
cleaner remove_timers
Browse files Browse the repository at this point in the history
  • Loading branch information
bmisiak committed Feb 26, 2024
1 parent aa6e8fa commit a75bea3
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,18 @@ pub(crate) fn delete_timer(timer_key: usize) -> Result<Option<Timer>, BorrowMutE
}

pub(crate) fn remove_timers(predicate: impl Fn(&Timer) -> bool) {
let mut removed_timers = Vec::new();
TIMERS.with_borrow_mut(|t| {
t.retain(|key, timer| {
if predicate(timer) {
removed_timers.push(key);
false
} else {
true
}
TIMERS.with_borrow_mut(|timers| {
QUEUE.with_borrow_mut(|queue| {
timers.retain(|key, timer| {
if predicate(timer) {
queue.remove(&key);
false
} else {
true
}
});
});
});
QUEUE.with_borrow_mut(|q| {
for key in removed_timers {
q.remove(&key);
}
});
}

fn deschedule_next_due(next_due: &NextDue) -> Result<(), TriggeringError> {
Expand Down

0 comments on commit a75bea3

Please sign in to comment.