Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action func()
Action is the simpliest event handler.
It won't receive the event value, and it can't report an error.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher dispatches an event to its subscribers.
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(e Event) []error
Dispatch dispatches an event to the relevant subscribers.
func (*Dispatcher) Subscribe ¶
func (d *Dispatcher) Subscribe(name string, s Subscriber) error
Subscribe subscribes a subscriber to an event type.
type ErrorStrategy ¶
type ErrorStrategy int
ErrorStrategy tells the dispatcher what to do when an error happens.
const ( // ErrorStrategyIgnore ignores the error. No error will be reported from Dispatch(). ErrorStrategyIgnore ErrorStrategy = iota // ErrorStrategyStop stops at the first error. ErrorStrategyStop // ErrorStrategyAggregate collects the errors, but keeps processing the subscribers. ErrorStrategyAggregate )
type Event ¶
type Event interface { // Name returns the machine name of the event. // This function should be idempotent. Name() string // ErrorStrategy tells the dispatcher how to behave when an error happens. // This function should be idempotent. ErrorStrategy() ErrorStrategy }
Event represents the events that will be dispatched to the subscribers.
type Subscriber ¶
Subscriber subscribes to an event.
type SubscriberFunc ¶
SubscriberFunc is a simple subscriber that is a function.
func (SubscriberFunc) Handle ¶
func (f SubscriberFunc) Handle(e Event) error
Handle handles an event.
Click to show internal directories.
Click to hide internal directories.