Skip to main content

Module watch

Module watch 

Source
Expand description

Watch-mode mechanics, behind one interface: folder watching, event relevance, and the trailing-edge debounce.

The module owns exactly the three mechanics mdo --watch needs; the render itself and how the CLI reports it belong to the caller, passed as a render callback. watch::run registers the watch, runs the callback once immediately, and then once per settled quiet window whenever the watched file plausibly changed content. A callback Err (e.g. a transient filesystem state mid-rename) is ignored and never ends watch mode, matching the CLI’s contract; channel death ends the watch gracefully.

Both the debounce timing and the loop clock are injectable at the pump level, so unit tests script fake event channels with a virtual clock and cover burst collapse, late events, sibling noise, watcher error storms, and channel death cross-platform by construction.

Functions§

run
Run watch mode for input: register a parent-directory watch, run render once immediately, then re-run it once per settled burst of events that plausibly changed the file’s content.