Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Watch ¶ added in v0.2.0
func Watch(dirs []string, debounce time.Duration, log *slog.Logger, onchange func() bool) (halt chan<- struct{}, err error)
Watch waits for changes to any of the directories in `dirs` (recursively), delays for `debounce` duration until no changes occurr within the window, and then calls onchange. Send a value to `halt` to exit early and cancel the watcher. Provide an optional logger.
After the first change event arrives, wait for further events until `debounce` delay passes with no events. This 'debounce' check tries to avoid a burst of reloads if multiple files are changed in quick succession (e.g. editor save all, or vcs checkout).
After waiting, a new watcher is constructed and the old one is closed. It's easier to recreate the watcher from scratch than to meticulously track and watch/unwatch directories as their events are received. A result of this design is that it may not be suited to watching thousands of directories, or directories that change frequently.
Types ¶
This section is empty.