Mountain/IPC/DevLog/FlushDedup.rs
1
2//! Flush the consecutive-duplicate buffer - emits a `(xN)` tail
3//! line if the pending count is greater than 1, then clears.
4
5use crate::IPC::DevLog::{DedupState, WriteToFile};
6
7pub fn Fn() {
8 // Use `try_lock` instead of `lock` so a contended flush (another
9 // dev_log! call holding the mutex) simply skips the dedup tail rather
10 // than parking the Tokio worker thread. The dedup compression is
11 // cosmetic; missing one flush never loses a log line.
12 let Ok(mut State) = DedupState::DEDUP.try_lock() else {
13 return;
14 };
15
16 if State.Count > 1 {
17 let Tail = format!(" (x{})", State.Count);
18
19 eprintln!("{}", Tail);
20
21 WriteToFile::Fn(&Tail);
22 }
23
24 State.LastKey.clear();
25
26 State.Count = 0;
27}