refactor: optimize worker loop to use try_recv for non-blocking event processing #5318
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use super::handle::Handle;
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::{retry, timing},
|
constants::{retry, timing},
|
||||||
logging,
|
logging,
|
||||||
@@ -91,22 +92,12 @@ impl NotificationSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn worker_loop(rx: mpsc::Receiver<FrontendEvent>) {
|
fn worker_loop(rx: mpsc::Receiver<FrontendEvent>) {
|
||||||
use super::handle::Handle;
|
|
||||||
|
|
||||||
let handle = Handle::global();
|
let handle = Handle::global();
|
||||||
|
|
||||||
while !handle.is_exiting() {
|
while !handle.is_exiting() {
|
||||||
match rx.recv() {
|
match rx.try_recv() {
|
||||||
Ok(event) => Self::process_event(handle, event),
|
Ok(event) => Self::process_event(handle, event),
|
||||||
Err(e) => {
|
Err(mpsc::TryRecvError::Disconnected) => break,
|
||||||
logging!(
|
Err(mpsc::TryRecvError::Empty) => break,
|
||||||
error,
|
|
||||||
Type::System,
|
|
||||||
"receive event error, stop notification worker: {}",
|
|
||||||
e
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user