Documentation
¶
Overview ¶
Package events provides typed, in-memory application events.
Index ¶
- Variables
- func Declare[T any](bus *Bus, definition Definition[T]) error
- func Publish[T any](ctx context.Context, bus *Bus, definition Definition[T], payload T) error
- func PublishAfterCommit[T any](ctx context.Context, bus *Bus, definition Definition[T], payload T) error
- func RequireDeclared[T any](bus *Bus, definition Definition[T]) error
- func Subscribe[T any](bus *Bus, definition Definition[T], subscriber string, handler Handler[T]) error
- type Bus
- type Deferrer
- type Definition
- type Delivery
- type Handler
- type Observer
- type Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrFrozen = errors.New("event bus is frozen") ErrTypeMismatch = errors.New("event definition type mismatch") ErrUndeclared = errors.New("event topic is not declared") ErrReentrant = errors.New("same-topic event publication is reentrant") ErrHandlerPanic = errors.New("event handler panicked") ErrHandlerTimeout = errors.New("event handler timed out") ErrSaturated = errors.New("event handler concurrency limit reached") ErrSubscriberLimit = errors.New("event topic subscriber limit reached") )
var ErrNoDeferral = errors.New("event deferral is unavailable")
ErrNoDeferral reports that no after-commit boundary is available, so the caller should dispatch immediately instead.
Functions ¶
func Declare ¶
func Declare[T any](bus *Bus, definition Definition[T]) error
Declare establishes a topic payload type before engine subscribers or publishers may use it. Direct event users may continue to rely on the historical lazy topic creation in Subscribe and Publish.
func Publish ¶
Publish invokes a topic's handlers serially for this publication. Separate publications may execute concurrently.
func PublishAfterCommit ¶
func PublishAfterCommit[T any](ctx context.Context, bus *Bus, definition Definition[T], payload T) error
PublishAfterCommit dispatches subscribers once the caller's database transaction commits, keeping subscriber latency out of the transaction and off the pooled connection it holds.
Subscribers observe committed state, so a failure cannot roll the transaction back; it surfaces through the host's after-commit error path. When no transaction is active, this falls back to immediate publication and behaves exactly like Publish.
func RequireDeclared ¶
func RequireDeclared[T any](bus *Bus, definition Definition[T]) error
RequireDeclared verifies that a topic was explicitly declared and that its payload type matches the caller's definition.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus stores in-memory event subscriptions. It does not persist, retry, or copy published payloads.
type Deferrer ¶
Deferrer schedules work to run after the caller's database transaction commits. It is injected so this package keeps no database dependency. Returning ErrNoDeferral means no transaction is active and the caller should dispatch immediately.
type Definition ¶
Definition identifies one version of a typed event. Name and Version form the runtime topic identity; T is checked when a topic is subscribed to or published.
func MustDefine ¶
func MustDefine[T any](name string, version int) Definition[T]
func (Definition[T]) Validate ¶
func (definition Definition[T]) Validate() error
type Option ¶
type Option func(*busSettings)
func WithDeferrer ¶
WithDeferrer supplies the after-commit scheduler used by PublishAfterCommit.