Fix busy loop
This commit is contained in:
parent
13d716924d
commit
d0caab03af
1 changed files with 5 additions and 5 deletions
|
@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue