Skip to content
This repository was archived by the owner on Aug 6, 2023. It is now read-only.

Commit 11df94d

Browse files
authored
fix(examples): avoid panic when computing event poll timeout in crossterm demo (#380)
1 parent 0abaa20 commit 11df94d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

examples/crossterm_demo.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ fn main() -> Result<(), Box<dyn Error>> {
5555
let mut last_tick = Instant::now();
5656
loop {
5757
// poll for tick rate duration, if no events, sent tick event.
58-
if event::poll(tick_rate - last_tick.elapsed()).unwrap() {
58+
let timeout = tick_rate
59+
.checked_sub(last_tick.elapsed())
60+
.unwrap_or_else(|| Duration::from_secs(0));
61+
if event::poll(timeout).unwrap() {
5962
if let CEvent::Key(key) = event::read().unwrap() {
6063
tx.send(Event::Input(key)).unwrap();
6164
}

0 commit comments

Comments
 (0)