internalWrites.ts
utils/settings/internalWrites.ts
No strong subsystem tag
38
Lines
1380
Bytes
3
Exports
0
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 38 lines, 0 detected imports, and 3 detected exports.
Important relationships
Detected exports
markInternalWriteconsumeInternalWriteclearInternalWrites
Keywords
pathtimestampssettingschangedetectormarkchokidarwritewindowmswatcherhooks
Detected imports
- No import paths detected.
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* Tracks timestamps of in-process settings-file writes so the chokidar watcher
* in changeDetector.ts can ignore its own echoes.
*
* Extracted from changeDetector.ts to break the settings.ts → changeDetector.ts →
* hooks.ts → … → settings.ts cycle. settings.ts needs to mark "I'm about to
* write" before the write lands; changeDetector needs to read the mark when
* chokidar fires. The map is the only shared state — everything else in
* changeDetector (chokidar, hooks, mdm polling) is irrelevant to settings.ts.
*
* Callers pass resolved paths. The path→source resolution (getSettingsFilePathForSource)
* lives in settings.ts, so settings.ts does it before calling here. No imports.
*/
const timestamps = new Map<string, number>()
export function markInternalWrite(path: string): void {
timestamps.set(path, Date.now())
}
/**
* True if `path` was marked within `windowMs`. Consumes the mark on match —
* the watcher fires once per write, so a matched mark shouldn't suppress
* the next (real, external) change to the same file.
*/
export function consumeInternalWrite(path: string, windowMs: number): boolean {
const ts = timestamps.get(path)
if (ts !== undefined && Date.now() - ts < windowMs) {
timestamps.delete(path)
return true
}
return false
}
export function clearInternalWrites(): void {
timestamps.clear()
}