refactor: optimize worker loop to use try_recv for non-blocking event processing #5318

This commit is contained in:
Tunglies
2025-11-05 22:58:05 +08:00
Unverified
parent 1bd2bde096
commit 6eaf999240

View File

@@ -1,3 +1,4 @@
use super::handle::Handle;
use crate::{
constants::{retry, timing},
logging,
@@ -91,22 +92,12 @@ impl NotificationSystem {
}
fn worker_loop(rx: mpsc::Receiver<FrontendEvent>) {
use super::handle::Handle;
let handle = Handle::global();
while !handle.is_exiting() {
match rx.recv() {
match rx.try_recv() {
Ok(event) => Self::process_event(handle, event),
Err(e) => {
logging!(
error,
Type::System,
"receive event error, stop notification worker: {}",
e
);
break;
}
Err(mpsc::TryRecvError::Disconnected) => break,
Err(mpsc::TryRecvError::Empty) => break,
}
}
}