events

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package events provides an in-process publish/subscribe event bus that implements the eventBus interface defined in the aitm package.

Index

Constants

View Source
const DefaultBufferSize = 64

DefaultBufferSize is the channel buffer size used when none is specified.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus is a goroutine-safe publish/subscribe bus backed by in-process Go channels.

Delivery guarantee: best-effort, in-process only. Events are never persisted. If a subscriber's channel is full when Publish is called, the event is dropped for that subscriber and a warning is logged. The publisher is never blocked.

func NewBus

func NewBus(bufSize int) *Bus

func (*Bus) Publish

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

Publish sends e to all subscribers registered for e.Type. e.OccurredAt is set to time.Now() before delivery regardless of what the caller provides. If a subscriber's channel is full the event is dropped for that subscriber and a warning is written to the default slog logger.

The read lock is held across the send loop to prevent Unsubscribe from closing a subscriber's channel between iteration and send (which would panic). Sends are non-blocking (select + default), so the critical section stays short: concurrent publishers still run in parallel, and an Unsubscribe call only waits for in-flight publishes to return.

func (*Bus) Subscribe

func (b *Bus) Subscribe(eventType sdk.EventType) (events <-chan aitm.Event, unsubscribe func())

Subscribe registers a subscriber for eventType and returns a buffered channel of events plus an unsubscribe function. The unsubscribe func is safe to call multiple times.

Jump to

Keyboard shortcuts

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