Documentation
¶
Overview ¶
Package folderwatch watches folders for changes and calls back once per burst, with holds that take folders out of the watch while the caller writes into them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Deps ¶
type Deps struct {
// Targets is read at start, on every Retarget tick and on every Changed signal; the folders it returns are
// exactly the ones watched. A target with an empty Dir is skipped.
Targets func() []Target
// Emit is called once per settled folder, from the watcher's own goroutine; it must not block.
Emit func(Target)
// Quiet is how long a folder stays unchanged before it settles. Zero or less means 500ms.
Quiet time.Duration
// Stable is how long a file written in place must keep its size before a settling target is announced. Zero
// or less means 1s.
Stable time.Duration
// Retarget is how often Targets is re-read, which also retries folders that did not exist. Zero or less means
// 2s.
Retarget time.Duration
// Changed re-reads Targets at once, so a folder is watched from the moment it becomes a target and a file that
// lands right after is not missed.
Changed <-chan struct{}
// Holds takes folders out of the watch while a caller moves them; nil holds none.
Holds *Holds
// Touched is called at once with the path of every change the watch sees, so a caller that caches what Targets
// found can drop it; nil ignores them.
Touched func(path string)
}
Deps wires the watcher to the caller's targets and callback.
type Holds ¶
type Holds struct {
// contains filtered or unexported fields
}
Holds takes folders out of the watch for a while. Windows refuses to move a folder while a watch has a handle open on it or on a folder below it, so a caller about to move one to the trash holds it first.
type Target ¶
type Target struct {
// Key names this folder in the caller's vocabulary; the watcher never interprets it.
Key string
// Dir is the folder to watch. Only its top level is watched, so a change deeper in the tree surfaces as a
// change to the folder holding it.
Dir string
// Report is the folder the change is reported under when it is not Dir, such as the root of a project whose
// subfolder changed. The watcher passes it back untouched; empty, the caller reports under Dir.
Report string
// Data is the caller's payload, passed back untouched.
Data any
// Settle announces a file written in place only once its size holds for Deps.Stable, so a writer that pauses
// mid-file is not mistaken for one that finished. A file renamed into the folder is announced on the first
// quiet tick either way.
Settle bool
}
Target is one folder to watch. The watcher hands the Target back unchanged when the folder settles, so Key names the change and Data is whatever the caller needs to make sense of it.