More consistent error handling in loops
This commit is contained in:
@ -3,7 +3,6 @@
|
||||
use log::*; //{trace, debug, info, warn, error}
|
||||
use anyhow::Result;
|
||||
use async_channel::{unbounded, Receiver, Sender};
|
||||
use std::panic;
|
||||
|
||||
use crate::dispatch;
|
||||
use crate::commands::Commands as Dispatch_Commands;
|
||||
@ -40,32 +39,19 @@ impl MotorDriverDebug {
|
||||
}
|
||||
|
||||
pub async fn run(&self) -> Result<()> {
|
||||
//TODO: Add error propagation to all loops
|
||||
loop {
|
||||
match self.recv_q.recv().await {
|
||||
Ok(cmd) => {
|
||||
match self.handle_cmd(cmd).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
error!("Unable to send commands to motor! {:?}", e);
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Unable to receive commands for motor control! {:?}", e);
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
let cmd = self.recv_q.recv().await.expect("Unexpected failure in motor driver command queue");
|
||||
self.handle_cmd(cmd).await.expect("Unexpected failure of motor driver notification queue");
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_cmd(&self, cmd: Commands) -> Result<()> {
|
||||
match cmd {
|
||||
Commands::StartUp => {self.start_up().await?;Ok(())}
|
||||
Commands::StartDown => {self.start_down().await?;Ok(())}
|
||||
Commands::Stop => {self.stop().await?;Ok(())}
|
||||
Commands::StartUp => {self.start_up().await?;}
|
||||
Commands::StartDown => {self.start_down().await?;}
|
||||
Commands::Stop => {self.stop().await?;}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn start_up(&self) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user