Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Dispatcher ¶
Dispatcher interface only has the Dispatch function
func NewGoDispatcher ¶
func NewGoDispatcher(provider Provider) Dispatcher
NewGoDispatcher returns an instance of Dispatcher Internally it uses the EventDispatcher
type EventDispatcher ¶
type EventDispatcher struct {
// contains filtered or unexported fields
}
EventDispatcher implements the Dispatcher interface and handles a default dispatching logic
func NewEventDispatcher ¶
func NewEventDispatcher(provider Provider) *EventDispatcher
NewEventDispatcher returns a new EventDispatcher
func (*EventDispatcher) Dispatch ¶
func (d *EventDispatcher) Dispatch(event Event) error
Dispatch a given event to all listeners provided by the listener If a listener returns an error no more listener gets called A listener gets the event returned by the previous listener if an Event is a type of StoppableEvent then no more listener get called
type GoDispatcher ¶
type GoDispatcher struct {
// contains filtered or unexported fields
}
func (*GoDispatcher) Dispatch ¶
func (d *GoDispatcher) Dispatch(event Event) error
Dispatch uses the EventDispatcher Dispatch method but runs it in a go routine
type Listener ¶
type Listener interface {
// Handle should accept an event and return an event and possible error
Handle(event Event) (Event, error)
}
Listener defines a listener
type ListenerFunc ¶
ListenerFunc is a wrapper for listener as functions and implements the Listener interface
type StoppableEvent ¶
type StoppableEvent interface {
Event
// IsPropagationStopped should tell the dispatcher that the propagation should be stopped
IsPropagationStopped() bool
// WithPropagationStopped returns a new event with the indicator that it should be stopped
WithPropagationStopped() StoppableEvent
}
StoppableEvent defines a specific kind of Event
type TreeProvider ¶
type TreeProvider struct {
// contains filtered or unexported fields
}
func NewTreeProvider ¶
func NewTreeProvider() *TreeProvider
NewTreeProvider returns a Provider which allows to listen to a set of events Eg. you got an Event mypackage.ModelTestEvent Now one can register to all events happening with "" or all events happening just in "mypackage" or all events of the model "mypackage.model" or explicit the event "mypackage.model.test" The provider will return from more global to more restrictive listeners
For the example above you would get the listeners in the following order listeners subscribed for "" listeners subscribed for "mypackage" listeners subscribed for "mypackage.model" listeners subscribed for "mypackage.model.test" each level returns their subscriber in the order they got them
func NewTreeProviderWithSeparator ¶
func NewTreeProviderWithSeparator(separator string) *TreeProvider
NewTreeProviderWithSeparator same as NewTreeProvider but specifying a custom separator is possible
func (*TreeProvider) Add ¶
func (t *TreeProvider) Add(listenTo string, listener Listener)
Add a listener to a "level". "" => all events
func (*TreeProvider) GetListenersForEvent ¶
func (t *TreeProvider) GetListenersForEvent(event Event) []Listener
GetListenersForEvent implementing the interface