events

package
v0.0.85 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package events implements the in-process Event Bus. Modules publish events after completing a state change. The bus fans out to all subscribers asynchronously via a bounded worker pool. Publish never blocks the caller — if the channel is full, the event is dropped and logged.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(ctx context.Context, b Bus)

Start launches the worker pool. Must be called before Publish. Stops when ctx is cancelled.

Types

type Bus

type Bus interface {
	// Publish emits an event to all registered subscribers.
	// It is non-blocking: the event is queued and processed asynchronously.
	Publish(ctx context.Context, event domain.Event)

	// Subscribe registers a handler for a specific event type.
	// Returns an unsubscribe function that removes the handler.
	Subscribe(eventType domain.EventType, handler HandlerFunc) (unsubscribe func())
}

Bus is the in-process publish/subscribe event bus.

func New

func New(workers, queueSize int) Bus

New creates an in-process Bus with the given worker count and queue capacity.

type HandlerFunc

type HandlerFunc func(ctx context.Context, event domain.Event) error

HandlerFunc is a function that processes a single event.

Jump to

Keyboard shortcuts

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