Skip to content

Commit

Permalink
perf(init): Stop polling for events
Browse files Browse the repository at this point in the history
Rather read events in a blocking fashion. This way we are not wasting on
useless CPU cycles
  • Loading branch information
AMythicDev committed Apr 23, 2024
1 parent 19213f9 commit 99d163d
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/core/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,28 +336,24 @@ fn event_reader(
}
}

if event::poll(std::time::Duration::from_millis(100))
.map_err(|e| MinusError::HandleEvent(e.into()))?
{
let ev = event::read().map_err(|e| MinusError::HandleEvent(e.into()))?;
let mut guard = ps.lock();
// Get the events
let input = guard.input_classifier.classify_input(ev, &guard);
if let Some(iev) = input {
if let InputEvent::Number(n) = iev {
guard.prefix_num.push(n);
guard.format_prompt();
} else if !guard.prefix_num.is_empty() {
guard.prefix_num.clear();
guard.format_prompt();
}
if let Err(TrySendError::Disconnected(_)) = evtx.try_send(Command::UserInput(iev)) {
break;
}
let ev = event::read().map_err(|e| MinusError::HandleEvent(e.into()))?;
let mut guard = ps.lock();
// Get the events
let input = guard.input_classifier.classify_input(ev, &guard);
if let Some(iev) = input {
if let InputEvent::Number(n) = iev {
guard.prefix_num.push(n);
guard.format_prompt();
} else if !guard.prefix_num.is_empty() {
guard.prefix_num.clear();
guard.format_prompt();
}
if let Err(TrySendError::Disconnected(_)) = evtx.try_send(Command::UserInput(iev)) {
break;
}
} else if !guard.prefix_num.is_empty() {
guard.prefix_num.clear();
guard.format_prompt();
}
}
Result::<(), MinusError>::Ok(())
Expand Down

0 comments on commit 99d163d

Please sign in to comment.