Skip to content

Commit

Permalink
guard against command failures
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjmeyer committed Jan 7, 2024
1 parent 997553e commit cb6a049
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/scope/analog_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ impl AnalogOutput {
});

// Send the command to the backend
self.command_tx.send(command).unwrap();
if self.command_tx.send(command).is_ok() {

// Wait for the response from the backend
let response_state = rx.recv().unwrap();
// Write the response state
*self.state.write().unwrap() = response_state;
// Wait for the response from the backend
if let Ok(response_state) = rx.recv() {
// Write the response state
*self.state.write().unwrap() = response_state;
}
}
}

pub fn is_on(&self) -> bool {
Expand Down
12 changes: 7 additions & 5 deletions src/scope/pulse_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ impl PulseOutput {
});

// Send the command to the backend
self.command_tx.send(command).unwrap();
if self.command_tx.send(command).is_ok() {

// Wait for the response from the backend
let response_state = rx.recv().unwrap();
// Write the response state
*self.state.write().unwrap() = response_state;
// Wait for the response from the backend
if let Ok(response_state) = rx.recv() {
// Write the response state
*self.state.write().unwrap() = response_state;
}
}
}

pub fn is_on(&self) -> bool {
Expand Down

0 comments on commit cb6a049

Please sign in to comment.