From 1fa07cb5ced69c406d432b26bf998d734f4047fc Mon Sep 17 00:00:00 2001 From: jtnunley Date: Sat, 8 Apr 2023 12:52:50 -0700 Subject: [PATCH] Use try-iter for processing timers --- Cargo.toml | 2 +- src/reactor.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 315447e..a1b2638 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ harness = false [dependencies] async-lock = "2.6" cfg-if = "1" -concurrent-queue = "2" +concurrent-queue = "2.2.0" futures-lite = "1.11.0" log = "0.4.11" parking = "2.0.0" diff --git a/src/reactor.rs b/src/reactor.rs index f49b345..b766c06 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -222,17 +222,17 @@ impl Reactor { fn process_timer_ops(&self, timers: &mut MutexGuard<'_, BTreeMap<(Instant, usize), Waker>>) { // Process only as much as fits into the queue, or else this loop could in theory run // forever. - for _ in 0..self.timer_ops.capacity().unwrap() { - match self.timer_ops.pop() { - Ok(TimerOp::Insert(when, id, waker)) => { + self.timer_ops + .try_iter() + .take(self.timer_ops.capacity().unwrap()) + .for_each(|op| match op { + TimerOp::Insert(when, id, waker) => { timers.insert((when, id), waker); } - Ok(TimerOp::Remove(when, id)) => { + TimerOp::Remove(when, id) => { timers.remove(&(when, id)); } - Err(_) => break, - } - } + }); } }