Merge pull request #114 from kdheepak/change-timeout

Change timeout to be between 10ms and 25ms
This commit is contained in:
Dheepak Krishnamurthy 2021-02-17 04:09:37 -07:00 committed by GitHub
commit 4defc10ffc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,14 +79,18 @@ impl Events {
thread::spawn(move || { thread::spawn(move || {
let mut last_tick = Instant::now(); let mut last_tick = Instant::now();
loop { loop {
if pause_stdin.load(Ordering::SeqCst) { if pause_stdin.load(Ordering::SeqCst) {
thread::sleep(Duration::from_millis(250)); thread::sleep(Duration::from_millis(250));
thread::park(); thread::park();
continue; continue;
} }
// poll for tick rate duration, if no event, sent tick event. let timeout = Duration::from_millis(25)
if event::poll(Duration::from_millis(10)).unwrap() { .checked_sub(last_tick.elapsed())
.unwrap_or_else(|| Duration::from_millis(10));
if event::poll(timeout).unwrap() {
if let event::Event::Key(key) = event::read().unwrap() { if let event::Event::Key(key) = event::read().unwrap() {
let key = match key.code { let key = match key.code {
Backspace => Key::Backspace, Backspace => Key::Backspace,