settingswatch

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 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

Overview

Package settingswatch applies a value-typed settings section to a live consumer, re-applying whenever the section changes. It is the lightweight counterpart to observers like payloadlog's Controller: those own sink/emitter lifecycle and rebuild their own resources, whereas a Watcher just reads one section and hands the resolved value to an apply callback.

Use it for knobs whose runtime effect is "call this setter with the new value" (e.g. a parser toggle). The callback is where any vendor-specific or impure coupling lives, so the watcher itself stays vendor-neutral and testable.

The watcher is event-driven: it applies the current value once at Start and then re-applies on each settings-change callback from the Source — no polling. Because the callback fires on the catalog's serial NOTIFY goroutine, the apply must be cheap (it is, for a setter); a consumer with heavy work should use payloadlog's signal-a-goroutine pattern instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

type Source interface {
	Setting(section string) (any, bool)
	OnSettingsChange(section string, fn func())
}

Source is a live settings provider: read a section's current value and subscribe to its changes. Satisfied by *app/catalog.Catalog.

type Watcher

type Watcher[T comparable] struct {
	// contains filtered or unexported fields
}

Watcher applies one settings section to a consumer via an apply callback, on first Start and on every subsequent change. T is the section's value type; it must be comparable so change detection is a plain ==.

func New

func New[T comparable](src Source, section string, apply func(T), log *slog.Logger) *Watcher[T]

New builds a Watcher for section. apply is called with the resolved value at Start and on every change. If apply panics it is recovered and logged so a bad value can't take down the caller (or the catalog listener goroutine the change callback runs on).

func (*Watcher[T]) Start

func (w *Watcher[T]) Start()

Start applies the current value once, then subscribes for changes. Synchronous and cheap; call it during composition after the catalog is wired. Reconcile order (apply-then-subscribe) guarantees at least one apply even if the section never changes; the mutex makes a change that races the initial apply safe.

Jump to

Keyboard shortcuts

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