bus

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package bus is the in-process event broker between the core and its clients. Publishing never blocks the agent loop: streaming lanes are lossy under a slow subscriber, control lanes are not.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus fans events out to subscribers.

func New

func New() *Bus

New returns an empty broker.

func (*Bus) Publish

func (b *Bus) Publish(ev event.Event)

Publish delivers ev to every matching subscriber under its lane's contract. On a Lossy lane a full buffer sheds its oldest event and the drop is counted; on a MustDeliver lane Publish waits until the subscriber drains or cancels.

func (*Bus) Subscribe

func (b *Bus) Subscribe(lane Lane, buffer int, types ...event.Type) *Sub

Subscribe registers a subscriber. buffer is the channel depth; types filters delivery to the listed event types, or everything when empty.

type Lane

type Lane int

Lane picks the delivery contract for a subscription.

const (
	// Lossy drops the oldest buffered event when a subscriber falls
	// behind. Streaming deltas ride this lane; a stalled TUI must never
	// stall the agent.
	Lossy Lane = iota
	// MustDeliver blocks the publisher until the subscriber drains.
	// Permission requests and terminal events ride this lane; dropping
	// one would wedge a turn.
	MustDeliver
)

type Sub

type Sub struct {
	C <-chan event.Event
	// contains filtered or unexported fields
}

Sub is one subscription. Receive from C in a select that also watches Done. C is never closed (a publisher may be mid-send when the subscription is cancelled); Done closing is the termination signal.

func (*Sub) Cancel

func (s *Sub) Cancel()

Cancel removes the subscription. Events already buffered in C stay readable; no new ones arrive after Done closes.

func (*Sub) Done

func (s *Sub) Done() <-chan struct{}

Done closes when the subscription is cancelled.

func (*Sub) Dropped

func (s *Sub) Dropped() uint64

Dropped reports how many events this subscription lost to backpressure. Always zero on a MustDeliver lane.

Jump to

Keyboard shortcuts

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