Skip to content

Commit

Permalink
Review poll timer logic for scheduled callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Jan 30, 2025
1 parent d90d02b commit b6ab444
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl EventLoop {
if let Some(timer) = guard_sched.peek() {
let tick = Instant::now().duration_since(self.epoch).as_micros();
if timer.when > tick {
let dt = ((timer.when - tick) / 1000) as u64;
let dt = (timer.when - tick) as u64;
sched_time = Some(dt);
}
}
Expand All @@ -128,7 +128,7 @@ impl EventLoop {
if sched_time.is_none() {
self.idle.store(true, atomic::Ordering::Release);
}
let res = io.poll(&mut state.events, sched_time.map(Duration::from_millis));
let res = io.poll(&mut state.events, sched_time.map(Duration::from_micros));
if let Err(ref err) = res {
if err.kind() == std::io::ErrorKind::Interrupted {
// if we got an interrupt, we retry ready events (as we might need to process signals)
Expand Down
2 changes: 1 addition & 1 deletion tests/handles/test_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def stop():
loop.stop()

loop.call_later(0.001, cb, 2)
loop.call_later(1.0, stop)
loop.call_later(0.1, stop)
loop.call_soon(cb, 1)
loop.run_forever()
assert calls == [1, 2]
Expand Down

0 comments on commit b6ab444

Please sign in to comment.