Skip to content

Commit 41d0c2a

Browse files
committed
Use try-iter for processing timers (#126)
1 parent 4753648 commit 41d0c2a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ harness = false
2525
[dependencies]
2626
async-lock = "2.6"
2727
cfg-if = "1"
28-
concurrent-queue = "2"
28+
concurrent-queue = "2.2.0"
2929
futures-lite = "1.11.0"
3030
log = "0.4.11"
3131
parking = "2.0.0"

src/reactor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,17 @@ impl Reactor {
222222
fn process_timer_ops(&self, timers: &mut MutexGuard<'_, BTreeMap<(Instant, usize), Waker>>) {
223223
// Process only as much as fits into the queue, or else this loop could in theory run
224224
// forever.
225-
for _ in 0..self.timer_ops.capacity().unwrap() {
226-
match self.timer_ops.pop() {
227-
Ok(TimerOp::Insert(when, id, waker)) => {
225+
self.timer_ops
226+
.try_iter()
227+
.take(self.timer_ops.capacity().unwrap())
228+
.for_each(|op| match op {
229+
TimerOp::Insert(when, id, waker) => {
228230
timers.insert((when, id), waker);
229231
}
230-
Ok(TimerOp::Remove(when, id)) => {
232+
TimerOp::Remove(when, id) => {
231233
timers.remove(&(when, id));
232234
}
233-
Err(_) => break,
234-
}
235-
}
235+
});
236236
}
237237
}
238238

0 commit comments

Comments
 (0)