Documentation
¶
Index ¶
- Constants
- type Event
- type EventBus
- func (e *EventBus) Publish(eventType EventType, evt Event)
- func (e *EventBus) RegisterSubscriber(eventType EventType, sub Subscriber) EventSubscriberId
- func (e *EventBus) Stop()
- func (e *EventBus) Subscribe(eventType EventType) (EventSubscriberId, <-chan Event)
- func (e *EventBus) SubscribeFunc(eventType EventType, handlerFunc EventHandlerFunc) EventSubscriberId
- func (e *EventBus) Unsubscribe(eventType EventType, subId EventSubscriberId)
- type EventHandlerFunc
- type EventSubscriberId
- type EventType
- type Subscriber
Constants ¶
const (
EventQueueSize = 20
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventBus ¶
func NewEventBus ¶
func NewEventBus( promRegistry prometheus.Registerer, logger *slog.Logger, ) *EventBus
NewEventBus creates a new EventBus
func (*EventBus) Publish ¶
Publish allows a producer to send an event of a particular type to all subscribers
func (*EventBus) RegisterSubscriber ¶ added in v0.18.0
func (e *EventBus) RegisterSubscriber( eventType EventType, sub Subscriber, ) EventSubscriberId
RegisterSubscriber allows external adapters (e.g., network-backed subscribers) to register with the EventBus. It returns the assigned subscriber id.
func (*EventBus) Stop ¶ added in v0.18.0
func (e *EventBus) Stop()
Stop closes all subscriber channels and clears the subscribers map. This ensures that SubscribeFunc goroutines exit cleanly during shutdown.
func (*EventBus) Subscribe ¶
func (e *EventBus) Subscribe( eventType EventType, ) (EventSubscriberId, <-chan Event)
Subscribe allows a consumer to receive events of a particular type via a channel
func (*EventBus) SubscribeFunc ¶
func (e *EventBus) SubscribeFunc( eventType EventType, handlerFunc EventHandlerFunc, ) EventSubscriberId
SubscribeFunc allows a consumer to receive events of a particular type via a callback function
func (*EventBus) Unsubscribe ¶
func (e *EventBus) Unsubscribe(eventType EventType, subId EventSubscriberId)
Unsubscribe stops delivery of events for a particular type for an existing subscriber
type EventHandlerFunc ¶
type EventHandlerFunc func(Event)
type EventSubscriberId ¶
type EventSubscriberId int
type Subscriber ¶ added in v0.18.0
Subscriber is a delivery abstraction that allows the EventBus to deliver events to in-memory channels and to network-backed subscribers via the same interface. Implementations must ensure Close() is idempotent and safe to call multiple times.