watcher

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package watcher provides file system watching with debouncing for the tracking database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DBPath      string
	DebounceDur time.Duration
}

Config holds watcher configuration options.

func DefaultConfig

func DefaultConfig(dbPath string) Config

DefaultConfig returns sensible defaults for the watcher.

type Watcher

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

Watcher monitors the tracking database for changes and publishes events via broker.

func New

func New(cfg Config) (*Watcher, error)

New creates a new database watcher.

func (*Watcher) Broker

func (w *Watcher) Broker() *pubsub.Broker[WatcherEvent]

Broker returns the pub/sub broker for subscribing to watcher events. The broker is created in New(), so it is always valid even before Start() is called.

func (*Watcher) Start

func (w *Watcher) Start() error

Start begins watching the database directory. Subscribe to watcher events using Broker().Subscribe(ctx) instead of the old channel return.

func (*Watcher) Stop

func (w *Watcher) Stop() error

Stop terminates the watcher and releases resources. CRITICAL SHUTDOWN SEQUENCE: broker.Close() must be called BEFORE fsWatcher.Close(). This ensures subscribers receive clean channel close notifications before the underlying fsnotify watcher is destroyed. Reversing this order could leave subscribers hanging.

type WatcherEvent

type WatcherEvent struct {
	Type  WatcherEventType
	Error error // Non-nil for WatcherError events
}

WatcherEvent represents an event from the database watcher.

type WatcherEventType

type WatcherEventType string

WatcherEventType identifies the kind of watcher event.

const (
	// DBChanged is emitted when the database file changes (after debounce).
	DBChanged WatcherEventType = "db_changed"
	// WatcherError is emitted when the watcher encounters an error (immediate, not debounced).
	WatcherError WatcherEventType = "error"
)

Jump to

Keyboard shortcuts

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