events

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 2 Imported by: 0 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

Overview

Package events provides the in-process broadcast hub behind GET /api/v1/events. One publisher fans an event out to every connected browser tab; nothing outside this process ever sees it, and nothing in this process depends on delivery succeeding.

The asymmetry is deliberate: a publish happens on an apply's critical path, while a subscriber is a browser tab that may have stopped reading at any moment. So publishing never blocks, never returns an error, and never waits on a reader -- a tab that falls behind loses events and repairs itself by resuming from Last-Event-ID.

Index

Constants

View Source
const (
	Heartbeat       = "heartbeat"
	ApplyCompleted  = "apply.completed"
	PlanInvalidated = "plan.invalidated"
	StatusChanged   = "status.changed"
	SeriesChanged   = "series.changed"
)

Event names. These are the wire values in the SSE `event:` field and the strings the client's bus switches on, so they are part of the contract -- see api/openapi.yaml's /events description.

history.appended from the design spec's catalog is deliberately absent: it would fire at the same instant, from the same place, carrying the same run_id as ApplyCompleted, and two events for one fact is a catalog that lies about its own granularity. If history ever grows a path that appends outside an apply, it earns its own event then.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	ID   int64
	Name string
	Data any
}

Event is one broadcast. Data is marshaled to JSON by the HTTP handler rather than here: the hub stays transport-agnostic, and a marshaling failure belongs to the one connection that hit it instead of to every subscriber.

type Hub

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

Hub fans events out to subscribers. The zero value is not usable; call NewHub.

func NewHub

func NewHub(buffer int) *Hub

NewHub returns a hub whose subscribers each get a channel buffered to buffer events. A non-positive buffer becomes 1, since an unbuffered channel would make every Publish drop for every subscriber that isn't blocked in a receive at that exact instant.

func (*Hub) LastID

func (h *Hub) LastID() int64

LastID returns the id of the most recent event, or 0 when none has been published.

func (*Hub) Publish

func (h *Hub) Publish(name string, data any)

Publish broadcasts an event to every current subscriber and records it in the resume ring. It never blocks and never fails: a subscriber whose buffer is full simply misses this event.

Callers publish AFTER the write they are announcing has committed. A tab that refetches on an event must not be able to outrun the data the event describes.

func (*Hub) Subscribe

func (h *Hub) Subscribe(ctx context.Context, lastID int64) (<-chan Event, func())

Subscribe registers a new subscriber and replays whatever the ring still holds past lastID, so a reconnecting client picks up where it left off. Pass lastID 0 for a fresh subscription.

The returned function unsubscribes and closes the channel; it is idempotent and safe to call from several goroutines. Canceling ctx does the same thing, so a dropped HTTP connection cleans itself up without the handler having to notice.

Jump to

Keyboard shortcuts

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