Skip to content

Commit

Permalink
cleaner state
Browse files Browse the repository at this point in the history
  • Loading branch information
bmisiak committed May 19, 2024
1 parent cce7094 commit fc4ef52
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) fn insert_and_schedule_timer(
timer: Timer,
get_schedule_based_on_key: impl FnOnce(usize) -> Schedule,
) -> usize {
STATE.with_borrow_mut(|&mut State { ref mut timers, ref mut queue }| {
STATE.with_borrow_mut(|State { timers, queue }| {
let key = timers.insert(timer);
let schedule = get_schedule_based_on_key(key);
let new_position = queue.partition_point(|s| s < &schedule);
Expand All @@ -44,7 +44,7 @@ pub(crate) fn insert_and_schedule_timer(
}

pub(crate) fn delete_timer(timer_key: usize) -> Result<(), TriggeringError> {
STATE.with_borrow_mut(|&mut State { ref mut timers, ref mut queue }| {
STATE.with_borrow_mut(|State { timers, queue }| {
ensure!(timers.contains(timer_key), TimerNotInQueue);
timers.remove(timer_key);
queue.retain(|s| s.key != timer_key);
Expand All @@ -53,7 +53,7 @@ pub(crate) fn delete_timer(timer_key: usize) -> Result<(), TriggeringError> {
}

pub(crate) fn reschedule_timer(key: usize, new_schedule: Schedule) -> Result<(), TriggeringError> {
STATE.with_borrow_mut(|&mut State { ref mut queue, .. }| {
STATE.with_borrow_mut(|State { queue, .. }| {
let current_index = queue
.iter()
.position(|s| s.key == key)
Expand All @@ -71,7 +71,7 @@ pub(crate) fn reschedule_timer(key: usize, new_schedule: Schedule) -> Result<(),
}

pub(crate) fn remove_timers(predicate: impl Fn(&Timer) -> bool) {
STATE.with_borrow_mut(|&mut State { ref mut timers, ref mut queue }| {
STATE.with_borrow_mut(|State { timers, queue }| {
let mut removed_keys = FnvHashSet::default();
queue.retain(|&Schedule { key, .. }| {
if predicate(&timers[key]) {
Expand All @@ -98,7 +98,7 @@ pub(crate) fn trigger_next_due_and_then<T>(
now: Instant,
timer_manipulator: impl Fn(&Timer) -> T,
) -> Option<T> {
STATE.with_borrow_mut(|&mut State { ref mut timers, ref mut queue }| {
STATE.with_borrow_mut(|State { timers, queue }| {
let Some(scheduled @ &Schedule { key, .. }) = queue.last() else {
return None;
};
Expand Down

0 comments on commit fc4ef52

Please sign in to comment.