Skip to content

Commit 393a821

Browse files
committed
More clear worker thread loop {} breaks.
1 parent 43897eb commit 393a821

4 files changed

Lines changed: 22 additions & 33 deletions

File tree

src/buffer/defmt/elf_watcher.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,25 @@ impl ElfWatchWorker {
158158
}
159159
}
160160
Err(TryRecvError::Empty) => (),
161-
Err(TryRecvError::Disconnected) => return Err(ElfWatchError::WatcherDisconnect),
161+
Err(TryRecvError::Disconnected) => break Err(ElfWatchError::WatcherDisconnect),
162162
}
163163

164164
match self.command_rx.try_recv() {
165165
Ok(ElfWatchCommand::Shutdown(shutdown_tx)) => {
166166
if let Err(_) = shutdown_tx.send(()) {
167167
error!("Failed to reply to shutdown request!");
168-
return Err(ElfWatchError::ShutdownReply);
168+
break Err(ElfWatchError::ShutdownReply);
169+
} else {
170+
return Ok(());
169171
}
170172
}
171173
Ok(command) => {
172174
self.handle_command(command)?;
173175
}
174176
Err(TryRecvError::Empty) => (),
175-
Err(TryRecvError::Disconnected) => return Err(ElfWatchError::HandleDropped),
177+
Err(TryRecvError::Disconnected) => break Err(ElfWatchError::HandleDropped),
176178
}
177-
break;
178179
}
179-
180-
Ok(())
181180
}
182181
fn event_matches_watched_file(&self, event: &notify::Event) -> bool {
183182
if let Some(watched_path) = &self.file_under_watch

src/buffer/logging.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ enum LoggingError {
8686
EventSend,
8787
#[error("failed to reply to shutdown request in time")]
8888
ShutdownReply,
89+
#[error("handle dropped, can't recieve commands")]
90+
HandleDropped,
8991
}
9092

9193
impl<T> From<SendError<T>> for LoggingError {
@@ -294,17 +296,15 @@ impl LoggingWorker {
294296
self.close_files(true)?;
295297
if let Err(_) = shutdown_tx.send(()) {
296298
error!("Failed to reply to shutdown request!");
297-
return Err(LoggingError::ShutdownReply);
299+
break Err(LoggingError::ShutdownReply);
300+
} else {
301+
break Ok(());
298302
}
299-
300-
break;
301303
}
302304
Ok(cmd) => self.handle_command(cmd)?,
303-
Err(RecvError) => {}
305+
Err(RecvError) => break Err(LoggingError::HandleDropped),
304306
}
305307
}
306-
307-
Ok(())
308308
}
309309
fn log_connection_event(
310310
&mut self,

src/event_carousel.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ impl CarouselWorker {
141141
if let Err(_) = shutdown_tx.send(()) {
142142
error!("Failed to reply to shutdown request!");
143143
return Err(CarouselError::ShutdownReply);
144+
} else {
145+
break Ok(());
144146
}
145-
146-
break;
147147
}
148148
Err(RecvTimeoutError::Timeout) => (),
149149
Err(RecvTimeoutError::Disconnected) => {
@@ -186,20 +186,14 @@ impl CarouselWorker {
186186
shortest.min(until_next_send)
187187
});
188188

189-
// Removing any expired oneshots
190-
self.events
191-
.retain(|e| e.event_type != EventType::ExpiredOneshot);
192-
193189
if send_error {
194-
break;
190+
break Err(CarouselError::EventTrigger);
195191
}
196192

193+
// Removing any expired oneshots
194+
self.events
195+
.retain(|e| e.event_type != EventType::ExpiredOneshot);
197196
// info!("Waiting for {sleep_time:?}");
198197
}
199-
if send_error {
200-
Err(CarouselError::EventTrigger)
201-
} else {
202-
Ok(())
203-
}
204198
}
205199
}

src/serial/worker.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ impl SerialWorker {
154154

155155
if let Err(_) = shutdown_tx.send(()) {
156156
error!("Failed to reply to shutdown request!");
157-
return Err(WorkerError::ShutdownReply);
157+
break Err(WorkerError::ShutdownReply);
158158
} else {
159-
break;
159+
break Ok(());
160160
}
161161
}
162162
Ok(SerialWorkerCommand::PortCommand(port_cmd)) => {
@@ -173,14 +173,11 @@ impl SerialWorker {
173173
Err(crossbeam::channel::RecvTimeoutError::Timeout) => (),
174174
Err(crossbeam::channel::RecvTimeoutError::Disconnected) => {
175175
error!("Serial worker handle got dropped! Shutting down!");
176-
break;
176+
break Err(WorkerError::HandleDropped);
177177
}
178178
}
179179

180180
if let Some(port) = self.port.as_mut_port() {
181-
// if port.bytes_to_read().unwrap() == 0 {
182-
// continue;
183-
// }
184181
// info!(
185182
// "bytes incoming: {}, bytes outcoming: {}",
186183
// port.bytes_to_read().unwrap(),
@@ -215,8 +212,6 @@ impl SerialWorker {
215212
}
216213
}
217214
}
218-
219-
Ok(())
220215
}
221216

222217
fn unhealthy_disconnection(&mut self) {
@@ -658,7 +653,6 @@ impl SerialWorker {
658653
// and the connection needs to be re-established.
659654
fn handle_esp_command(&mut self, esp_command: EspCommand) -> Result<(), WorkerError> {
660655
if !self.port.is_native() {
661-
// TODO decide if i wanna keep this or just return Ok(())
662656
error!("ESP Command given when we don't own native port!");
663657
return Err(WorkerError::MissingPort);
664658
}
@@ -1001,6 +995,8 @@ pub(crate) enum WorkerError {
1001995
FailedSend,
1002996
#[error("failed to reply to shutdown request in time")]
1003997
ShutdownReply,
998+
#[error("handle dropped, can't recieve commands")]
999+
HandleDropped,
10041000

10051001
#[cfg(feature = "espflash")]
10061002
#[error("espflash error: {0}")]

0 commit comments

Comments
 (0)