Documentation
¶
Overview ¶
Package memory implements an in-process event bus with sync/async dispatch, wildcard topic matching, and middleware support.
Index ¶
- type Bus
- func (b *Bus) Close() error
- func (b *Bus) Metrics() eventbus.Metrics
- func (b *Bus) Publish(ctx context.Context, e *eventbus.Event) error
- func (b *Bus) Subscribe(topic string, handler eventbus.Handler) eventbus.Subscription
- func (b *Bus) SubscriberCount(topic string) int
- func (b *Bus) Topics() []string
- func (b *Bus) Unsubscribe(sub eventbus.Subscription) error
- type DispatchMode
- type Option
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 is an in-memory event bus.
func (*Bus) Subscribe ¶
Subscribe registers a handler for the given topic pattern. Returns a Subscription that can be used with Unsubscribe.
func (*Bus) SubscriberCount ¶
SubscriberCount returns the number of subscribers for a topic pattern.
func (*Bus) Unsubscribe ¶
func (b *Bus) Unsubscribe(sub eventbus.Subscription) error
Unsubscribe removes a subscription.
type DispatchMode ¶
type DispatchMode int
DispatchMode controls how events are delivered to handlers.
const ( // Sync dispatches events synchronously — Publish blocks until all // handlers complete. Errors from one handler stop delivery to // subsequent handlers. Sync DispatchMode = iota // Async dispatches events in goroutines — Publish returns immediately // after enqueuing. Handler errors are collected but not returned to // the publisher. Async // Parallel dispatches events to all handlers concurrently in // separate goroutines, then waits for all to complete. Publish // blocks until all handlers finish. Parallel )
type Option ¶
type Option func(*Bus)
Option configures the Bus.
func WithAsyncBufferSize ¶
WithAsyncBufferSize sets the buffer size for async dispatch. Only effective with Async mode. Default: 1024.
func WithDispatchMode ¶
func WithDispatchMode(mode DispatchMode) Option
WithDispatchMode sets the dispatch mode (default: Sync).
func WithMiddleware ¶
func WithMiddleware(mw ...eventbus.Middleware) Option
WithMiddleware adds middleware applied to all handlers.