More consistent error handling in loops
This commit is contained in:
@ -70,7 +70,7 @@ impl<Q: PartialEq, S: Copy> MessageTimer<Q, S> {
|
||||
}
|
||||
|
||||
async fn wait_for_cmd(&self) -> Result<Q> {
|
||||
Ok(self.recv_q.recv().await.unwrap())
|
||||
Ok(self.recv_q.recv().await.expect("Timer command queue unexpectedly failed"))
|
||||
}
|
||||
|
||||
async fn wait_with_timeout(&self, timer: &mut EspAsyncTimer) -> Result<Q> {
|
||||
@ -101,18 +101,17 @@ impl<Q: PartialEq, S: Copy> MessageTimer<Q, S> {
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) -> Result<()> {
|
||||
let mut cmd;
|
||||
let timer_service = EspTaskTimerService::new()?;
|
||||
let mut async_timer = timer_service.timer_async()?;
|
||||
loop {
|
||||
match self.state {
|
||||
let cmd = match self.state {
|
||||
State::Running => {
|
||||
cmd = self.wait_with_timeout(&mut async_timer).await;
|
||||
self.wait_with_timeout(&mut async_timer).await
|
||||
}
|
||||
State::Stopped => {
|
||||
cmd = self.wait_for_cmd().await;
|
||||
self.wait_for_cmd().await
|
||||
}
|
||||
}
|
||||
};
|
||||
self.handle_cmd(cmd).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user