watcher

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DebouncedEvent

type DebouncedEvent struct {
	Path string
	Op   EventOp
}

DebouncedEvent represents a batched file system event.

type Debouncer

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

Debouncer collects file system events and emits batched events after a quiet period. Multiple events for the same path within the debounce window are collapsed into one.

func NewDebouncer

func NewDebouncer(interval time.Duration) *Debouncer

NewDebouncer creates a debouncer with the specified quiet interval.

func (*Debouncer) Add

func (d *Debouncer) Add(path string, op EventOp)

Add adds an event to the debounce window. If an event for the same path already exists, it is replaced with the latest operation.

func (*Debouncer) Output

func (d *Debouncer) Output() <-chan []DebouncedEvent

Output returns the channel that receives batched events.

type EventOp

type EventOp int

EventOp represents the type of file system operation.

const (
	OpCreate EventOp = iota
	OpWrite
	OpRemove
	OpRename
)

type IgnoreChecker

type IgnoreChecker interface {
	ShouldIgnoreDir(absolutePath string) bool
	ShouldIgnore(absolutePath string) bool
}

IgnoreChecker is used by the watcher to check if a path should be ignored.

type Watcher

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

Watcher provides recursive file system watching with debouncing.

func NewWatcher

func NewWatcher(rootDir string, ignoreChecker IgnoreChecker, logger *slog.Logger) (*Watcher, error)

NewWatcher creates a recursive file watcher on the given root directory. It registers all non-ignored subdirectories for watching.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the watcher and releases resources.

func (*Watcher) Events

func (w *Watcher) Events() <-chan []DebouncedEvent

Events returns the channel that receives debounced file system events.

func (*Watcher) Start

func (w *Watcher) Start()

Start begins listening for file system events. Call this in a goroutine. It runs until the watcher is closed.

Jump to

Keyboard shortcuts

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