Help us shape the future of Go! Take the 2026 Go Developer Survey

fswatch

package
v0.66.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package fswatch watches a directory tree and reports which directories changed. fsnotify has no recursive watch, so the watcher holds one watch per directory and keeps that set in step with the tree. It reports directories rather than files because its consumer re-reads a changed directory instead of applying event deltas.

Symbolic links below the root are not followed: a linked directory is neither walked nor watched. The root itself may be a link. Directories whose names start with "." are not watched, which keeps .git, .obsidian, and .hive out of the set.

Index

Constants

View Source
const DefaultDebounce = 100 * time.Millisecond

DefaultDebounce coalesces the write, rename, and chmod burst of one editor save into one Change, and so into one rescan.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	Dirs   []string
	Resync bool
}

Change lists the absolute directories whose listing or files changed since the previous Change, sorted. A created directory is listed itself as well as through its parent: files written into it before its watch existed produced no events, so the consumer has to read it.

Resync reports that the kernel dropped events, so Dirs lists every watched directory and the consumer must re-read everything it holds, not only those directories' listings.

type Option

type Option func(*options)

func WithDebounce

func WithDebounce(d time.Duration) Option

WithDebounce sets the window that collects events into one Change. The window opens at the first event after the previous one closed and closes d later, so a continuous writer still yields a Change every d. Default DefaultDebounce.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher delivers one Change per debounce window on an unbuffered channel. It never blocks on its consumer: windows that close while the consumer is busy merge into the Change it receives next.

When the root itself is removed or renamed, the watcher stops and Changes closes, as after Close: every watch is gone with the root, and a new one can only be added once something creates the root again. The consumer starts a new Watcher then.

func New

func New(logger zerolog.Logger, root string, opts ...Option) (*Watcher, error)

New walks root, adds one fsnotify watch per directory, and starts the pump.

func (*Watcher) Changes

func (w *Watcher) Changes() <-chan Change

Changes is closed after Close, or once the root is removed or renamed.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the pump and releases every watch. It is idempotent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL