pubsub

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package pubsub provides a generic publish-subscribe event broker for decoupled communication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

type Broker[T any] struct {
	// contains filtered or unexported fields
}

Broker manages subscriptions and event publishing for a specific type

func NewBroker

func NewBroker[T any]() *Broker[T]

NewBroker creates a new event broker

func (*Broker[T]) Publish

func (b *Broker[T]) Publish(eventType EventType, payload T)

Publish sends an event to all subscribers

func (*Broker[T]) Subscribe

func (b *Broker[T]) Subscribe(ctx context.Context) <-chan Event[T]

Subscribe creates a new subscription that receives events until context is cancelled

type Event

type Event[T any] struct {
	Type    EventType
	Payload T
}

Event wraps a payload with its event type

type EventType

type EventType int

EventType represents the type of event being published

const (
	Created EventType = iota
	Updated
	Deleted
)

Event type constants for common CRUD operations

type Subscriber

type Subscriber[T any] interface {
	Subscribe(ctx context.Context) <-chan Event[T]
}

Subscriber interface for services that publish events

Jump to

Keyboard shortcuts

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