watcher

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRegistered = errors.New("path is already registered; call Unwatch before registering it again")

ErrAlreadyRegistered reports that a path already has a Watch or Poll registration. Call Unwatch before registering the same normalized path again.

View Source
var ErrClosed = errors.New("file watcher is closed")

ErrClosed reports that Watch or Poll was called after the watcher closed.

Functions

This section is empty.

Types

type FileWatcher

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

FileWatcher watches database files for changes.

func NewFileWatcher

func NewFileWatcher() (*FileWatcher, error)

NewFileWatcher creates a new file watcher.

func (*FileWatcher) Close

func (fw *FileWatcher) Close() error

Close cancels future watcher work, pending debounce timers, and pollers. Repeated and concurrent calls return the same result. A callback that was already claimed may finish after Close returns, which keeps Close safe when it is called synchronously from inside that callback.

func (*FileWatcher) Poll

func (fw *FileWatcher) Poll(path string, callback func(string), interval time.Duration) error

Poll checks a local file or URL on an interval and invokes callback after content changes. It is primarily used for remote database sources.

func (*FileWatcher) Start

func (fw *FileWatcher) Start()

Start begins watching for local file changes.

func (*FileWatcher) Unwatch

func (fw *FileWatcher) Unwatch(path string) error

Unwatch prevents future callbacks from being claimed for path and cancels its poller or pending debounce timer. A callback already claimed before the removal may still start or finish after Unwatch returns. This non-blocking teardown makes it safe for a callback to unwatch itself.

func (*FileWatcher) Watch

func (fw *FileWatcher) Watch(path string, callback func(string), debounceDuration time.Duration) error

Watch starts watching a local file with a configurable debounce duration.

Jump to

Keyboard shortcuts

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