Documentation
¶
Overview ¶
Package events is the domain-event spine: a single typed, causation-aware bus that any part of Vega can publish onto and subscribe to. The SSE broker and worker telemetry become projections of it; the reactive trigger router is a third subscriber. See docs/reactive-agents-design.md (decision D3).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithOrigin ¶
ContextWithOrigin attaches the causation an event should carry if it is emitted during work done on ctx's behalf. The reactive router sets this on a wake's context so any events the wake emits inherit its chain depth.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is an in-process publish/subscribe spine. Publish is non-blocking with respect to every subscriber regardless of delivery mode.
Durability here means guaranteed in-process, in-order delivery to durable subscribers. Cross-restart persistence (an events table with replay) is a later layer behind this same interface — see design §8 open decision #1.
func (*Bus) Publish ¶
Publish stamps the event's ID and Time if unset, delivers it to every matching subscriber, and returns the stamped event.
func (*Bus) Subscribe ¶
func (b *Bus) Subscribe(mode DeliveryMode, filter func(Event) bool) *Subscription
Subscribe registers a subscriber. If filter is non-nil, only events for which it returns true are delivered. Read from the returned Subscription's C channel; call Close when done.
type DeliveryMode ¶
type DeliveryMode int
DeliveryMode controls how a subscriber tolerates backpressure.
const ( // Lossy drops events when the subscriber's buffer is full rather than // blocking the publisher. Correct for a UI that can miss a frame. Lossy DeliveryMode = iota // Durable never drops: events queue without bound until delivered, in // order. Correct for reactive triggers, which must not miss a creak. Durable )
type Event ¶
Event is a single occurrence on the spine. Type is a dotted noun.verb string (e.g. "agent.completed"). Data carries the event-specific payload. ID and Time are stamped by the bus at Publish if left zero.
type Origin ¶
type Origin struct {
EventID string // the event that triggered the run that emitted this one
AgentName string // the agent whose reactive run emitted it
Depth int // reactive-chain depth
}
Origin carries typed causation — what caused this event. It is nil for external/root events (a human message, a cron fire, a sensor). When a reactive run emits events, they inherit the triggering event's Origin with Depth incremented, which is what the loop guard uses to cap reactive chains (design D2 / §5.3).
func OriginFromContext ¶
OriginFromContext returns the causation attached to ctx, or nil for a root context (a human message, a cron fire, an external sensor).
type Subscription ¶
type Subscription struct {
C <-chan Event
// contains filtered or unexported fields
}
Subscription is a handle to a stream of events. Read from C.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close stops delivery to this subscription and closes C.