Expand description
Event-driven file watcher (issue #526).
Wraps [notify::recommended_watcher] so the dev server can react to
OS filesystem events (FSEvents / inotify / ReadDirectoryChangesW)
instead of polling. Compared to the legacy crate::watch::FileWatcher,
this:
- Costs ~0% idle CPU (kernel pushes events; no
mtimescan loop). - Wakes within ~5 ms of the OS event vs. the 1-2 s polling interval.
- Coalesces rapid saves through a 100 ms debounce window — a
cargo fmtstorm that touches one file four times in 200 ms produces exactly one drain (AC6).
§Architecture
notify backend ──▶ raw_tx ──▶ debounce thread ──▶ batched_tx ──▶ caller
(OS event) mpsc (100 ms window) mpscThe debounce thread:
- Blocks on
raw_rx.recv()until the first event arrives. - Records the wall-clock instant of that first event.
- Drains every subsequent event with
recv_timeout(remaining)until 100 ms have elapsed since the first event. - Sends the de-duplicated path set to
batched_tx.
Last-write-wins is implicit: only the path set is forwarded, the per-event ordering is discarded.
§Why not notify-debouncer-mini?
That crate brings a tokio dep transitively; ssg is rayon-only. The
hand-rolled debouncer here is ~30 lines, deterministic, and unit-testable
without touching the filesystem (see debounce_paths).
Structs§
- Change
Batch - A batched set of changed paths produced by
EventWatcher. - Event
Watcher - Event-driven watcher built on top of
notify.
Enums§
- Recv
Outcome - Result of a
EventWatcher::recv_timeoutcall.
Constants§
- DEFAULT_
DEBOUNCE - Default debounce window. 100 ms is the issue-#526 AC6 target — long
enough to collapse a
cargo fmtsave storm into one rebuild, short enough to feel instant in the browser. - MAX_
BATCH_ PATHS - Cap on how many distinct paths can be debounced into a single batch before the watcher forces a drain. Prevents pathological build-output storms from delaying delivery beyond a reasonable bound.
Functions§
- debounce_
paths - Pure helper: collapse a stream of
(path, instant)events into a list of debounced batches. Used by tests so the debouncer logic can be verified without spawning threads. - event_
should_ propagate - Returns whether a notify event represents a real change.