Fix busy loop

This commit is contained in:
zaubentrucker 2025-02-22 22:35:54 +01:00
parent 13d716924d
commit d0caab03af

View file

@ -389,7 +389,7 @@ impl Printer {
// Bytes that were read from the port that don't constitute a whole line
let mut partial_reads: Vec<u8> = Vec::new();
loop {
match from_user_thread.try_recv() {
match from_user_thread.recv_timeout(Duration::from_millis(10)) {
Ok(user_command) => handle_user_command(
&mut port,
user_command,
@ -397,9 +397,9 @@ impl Printer {
&mut partial_reads,
to_user_thread.clone(),
),
Err(TryRecvError::Disconnected) => break,
Err(TryRecvError::Empty) => {
handle_printer_autoreport(&mut port, &mut partial_reads, state.clone())
Err(RecvTimeoutError::Disconnected) => break,
Err(RecvTimeoutError::Timeout) => {
handle_printer_autoreport(&mut port, &mut partial_reads, state.clone());
}
}
}
@ -492,7 +492,7 @@ fn handle_printer_autoreport(
eprintln!(
"ERROR: Got line from printer outside of command!: {}",
str_line
)
);
}
}