eventbus

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package eventbus provides a synchronous, typed event bus for decoupling components that currently rely on scattered SetXxxCallback() wiring.

Events are dispatched synchronously in registration order. The bus is safe for concurrent use; Subscribe takes a write lock, Publish takes a read lock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SubscribeTyped

func SubscribeTyped[T Event](bus *Bus, handler func(T))

SubscribeTyped is a generic helper that provides type-safe subscription. It registers a handler that automatically type-asserts the event before calling the typed handler function.

Types

type Bus

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

Bus is a synchronous typed event bus.

func New

func New() *Bus

New creates a new event bus.

func (*Bus) Publish

func (b *Bus) Publish(event Event)

Publish sends an event to all registered handlers synchronously. If no handlers are registered for the event, it is silently ignored.

func (*Bus) Subscribe

func (b *Bus) Subscribe(eventName string, handler HandlerFunc)

Subscribe registers a handler for a specific event name.

type ContentSavedEvent

type ContentSavedEvent struct {
	ID         string
	Collection string
	Content    string
	Metadata   map[string]string
	Source     string // "knowledge" or "memory"
}

ContentSavedEvent is published when knowledge or memory content is saved. Replaces: SetEmbedCallback, SetGraphCallback on knowledge and memory stores.

func (ContentSavedEvent) EventName

func (e ContentSavedEvent) EventName() string

EventName implements Event.

type Event

type Event interface {
	EventName() string
}

Event is implemented by all event types.

type HandlerFunc

type HandlerFunc func(event Event)

HandlerFunc processes an event.

type MemoryGraphEvent

type MemoryGraphEvent struct {
	Triples    []Triple
	SessionKey string
	Type       string // "observation" or "reflection"
}

MemoryGraphEvent is published when memory graph hooks fire. Replaces: memory.Store.SetGraphHooks.

func (MemoryGraphEvent) EventName

func (e MemoryGraphEvent) EventName() string

EventName implements Event.

type ReputationChangedEvent

type ReputationChangedEvent struct {
	PeerDID  string
	NewScore float64
}

ReputationChangedEvent is published when a peer's reputation changes. Replaces: reputation.Store.SetOnChangeCallback.

func (ReputationChangedEvent) EventName

func (e ReputationChangedEvent) EventName() string

EventName implements Event.

type Triple

type Triple struct {
	Subject   string
	Predicate string
	Object    string
	Metadata  map[string]string
}

Triple mirrors graph.Triple to avoid an import dependency on the graph package, keeping the eventbus package dependency-free.

type TriplesExtractedEvent

type TriplesExtractedEvent struct {
	Triples []Triple
	Source  string // e.g. "learning", "analysis", "librarian"
}

TriplesExtractedEvent is published when graph triples are extracted. Replaces: SetGraphCallback on learning engines and analyzers.

func (TriplesExtractedEvent) EventName

func (e TriplesExtractedEvent) EventName() string

EventName implements Event.

type TurnCompletedEvent

type TurnCompletedEvent struct {
	SessionKey string
}

TurnCompletedEvent is published when a gateway turn completes. Replaces: Gateway.OnTurnComplete callbacks.

func (TurnCompletedEvent) EventName

func (e TurnCompletedEvent) EventName() string

EventName implements Event.

Jump to

Keyboard shortcuts

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