perf: use blocking recv method reduce unnecessary polling overhead.

This commit is contained in:
oomeow
2025-12-13 16:10:15 +08:00
parent 5c42658a2e
commit c5fa64a213

View File

@@ -9,7 +9,7 @@ use std::{
mpsc, mpsc,
}, },
thread, thread,
time::{Duration, Instant}, time::Instant,
}; };
use tauri::{Emitter as _, WebviewWindow}; use tauri::{Emitter as _, WebviewWindow};
@@ -85,15 +85,17 @@ impl NotificationSystem {
} }
fn worker_loop(rx: mpsc::Receiver<FrontendEvent>) { fn worker_loop(rx: mpsc::Receiver<FrontendEvent>) {
let handle = Handle::global();
loop { loop {
let handle = Handle::global();
if handle.is_exiting() { if handle.is_exiting() {
break; break;
} }
match rx.recv_timeout(Duration::from_millis(1_000)) { match rx.recv() {
Ok(event) => Self::process_event(handle, event), Ok(event) => Self::process_event(handle, event),
Err(mpsc::RecvTimeoutError::Timeout) => (), Err(e) => {
Err(mpsc::RecvTimeoutError::Disconnected) => break, logging!(error, Type::System, "Notification System will exit, recv error: {}", e);
break;
}
} }
} }
} }