eventbus

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package eventbus is an in-process pub/sub hub for UI state-change events.

Mutations anywhere in the codebase (CLI commands, HTTP handlers, file watchers) call Publish to announce that a kind of state has changed. The hub debounces rapid publishes and broadcasts a single Event to every Subscriber. The ui package subscribes from the /api/ws handler so the browser can update without polling.

Index

Constants

View Source
const (
	KindSites    = "sites"
	KindServices = "services"
	KindStatus   = "status"
)

Event kinds. Callers should use these constants rather than raw strings.

Variables

View Source
var Default = New()

Default is the process-wide Hub used by publishers that don't carry their own hub reference.

Functions

This section is empty.

Types

type Event

type Event struct {
	Kinds []string
	At    time.Time
}

Event is broadcast to every Subscriber when a publish fires.

type Hub

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

Hub coalesces publishes and fans them out to subscribers.

func New

func New() *Hub

New returns a Hub with the default 150ms debounce window.

func (*Hub) Publish

func (h *Hub) Publish(kind string)

Publish marks kind dirty and (re)arms the debounce timer. Multiple publishes within the debounce window collapse into one broadcast.

func (*Hub) SetDebounce

func (h *Hub) SetDebounce(d time.Duration)

SetDebounce changes the debounce window. Intended for tests.

func (*Hub) Subscribe

func (h *Hub) Subscribe() *Subscriber

Subscribe registers a new subscriber with a buffered channel.

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(s *Subscriber)

Unsubscribe removes s and closes its channel if not already closed.

type Subscriber

type Subscriber struct {
	C chan Event
	// contains filtered or unexported fields
}

Subscriber receives events via C. Slow subscribers whose buffer fills up are dropped: the hub closes C and removes the subscriber.

Jump to

Keyboard shortcuts

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