events

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package events provides a lightweight in-process event bus for publishing domain events between modules. For cross-process events, replace this with a message queue adapter (e.g. Redis Streams, NATS, or Kafka).

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 dispatches events to registered handlers.

func New

func New() *Bus

New creates a new event bus.

func (*Bus) Publish

func (b *Bus) Publish(ctx context.Context, event Event) error

Publish dispatches an event synchronously to all registered handlers. Returns the first error encountered, if any.

func (*Bus) Subscribe

func (b *Bus) Subscribe(eventName string, h Handler)

Subscribe registers a handler for a specific event name.

type Event

type Event interface {
	// EventName returns a dot-separated identifier, e.g. "deployment.created".
	EventName() string
}

Event is the base interface for all domain events.

type Handler

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

Handler is a function that processes an event.

Jump to

Keyboard shortcuts

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