Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/DevLog/
FlushDedup.rs

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