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 ¶
const ( KindSites = "sites" KindServices = "services" KindStatus = "status" )
Event kinds. Callers should use these constants rather than raw strings.
Variables ¶
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 Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub coalesces publishes and fans them out to subscribers.
func (*Hub) Publish ¶
Publish marks kind dirty and (re)arms the debounce timer. Multiple publishes within the debounce window collapse into one broadcast.
func (*Hub) SetDebounce ¶
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.