Documentation
¶
Overview ¶
Package events dispatches typed events to listeners registered by type. Listeners are plain functions; registration is explicit code (no discovery):
type UserRegistered struct{ User models.User }
bus.Register(events.On(listeners.SendWelcome)) // func(ctx, UserRegistered) error
err := bus.Dispatch(ctx, UserRegistered{User: u})
Async listeners run on a bounded goroutine pool that Shutdown drains; a queue-backed mode arrives with the queue (BETA).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("events: bus is shut down")
ErrClosed is returned by Dispatch after Shutdown.
Functions ¶
func Dispatched ¶
Dispatched returns the recorded events of type E.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus holds listeners and runs them.
func (*Bus) Dispatch ¶
Dispatch runs the synchronous listeners of event's type in registration order (stopping at the first error) and schedules the async ones. Events without listeners are fine.
func (*Bus) Register ¶
func (b *Bus) Register(regs ...Registration)
Register adds listeners in order.
type Dispatcher ¶
Dispatcher dispatches events (Bus and Fake implement it).
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake records dispatched events instead of running listeners (tests).
type Registration ¶
type Registration struct {
// contains filtered or unexported fields
}
Registration binds a listener to its event type; create it with On or OnAsync.