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

watch

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package watch schedules continuous verification without choosing a verification engine. Callers supply observation, analysis, and rendering functions.

Index

Constants

View Source
const (
	Changed    = "changed"
	Checking   = "checking"
	Completed  = "completed"
	Attributed = "attributed"
	Error      = "error"
	Heartbeat  = "heartbeat"
)

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, options Options, observe Observe, analyze Analyze, emit Emit) error

Run uses one analysis worker and coalesces changes until the debounce period expires. Analyze must honor cancellation and release its temporary resources before returning. Run waits for that cleanup on shutdown and returns ctx.Err(). Observation and emission also must return promptly or honor cancellation.

Types

type Analyze

type Analyze func(context.Context, State) (Result, error)

type Emit

type Emit func(Event)

type Event

type Event struct {
	Type     string    `json:"type"`
	Sequence uint64    `json:"sequence"`
	Time     time.Time `json:"time"`
	State    State     `json:"state"`
	Result   *Result   `json:"result,omitempty"`
	Error    string    `json:"error,omitempty"`
}

Event is delivered synchronously, in sequence order. A completed event always refers to inputs reobserved after analysis; a changed event invalidates the previous result immediately. Heartbeats deliberately contain no old result.

type Observe

type Observe func(context.Context) (State, error)

type Options

type Options struct {
	Interval  time.Duration
	Debounce  time.Duration
	Heartbeat time.Duration
}

type Result

type Result struct {
	Value any `json:"value,omitempty"`
	// Followup performs slower observations after the initial result is emitted.
	// It uses the same bounded worker slot and cancellation scope as Analyze.
	Followup func(context.Context) (Result, error) `json:"-"`
	// Close releases retained resources after followup or when superseded.
	Close func() `json:"-"`
}

type State

type State struct {
	Key   string `json:"key"`
	Value any    `json:"value,omitempty"`
}

State identifies all inputs relevant to a check. Value belongs to the caller; it must remain immutable while analysis is running. Key must be nonempty.

Jump to

Keyboard shortcuts

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