Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher is a distributor of events to registered handlers. A handler is a event-type-specific function that takes the concrete type of an event as a parameter.
func (*Dispatcher) Event ¶
func (dispatcher *Dispatcher) Event(e Event)
Event dispatches the given event to all currently registered handlers.
func (*Dispatcher) RegisterHandler ¶
func (dispatcher *Dispatcher) RegisterHandler(handlerFunc interface{}) func()
RegisterHandler must be called a function that takes one argument which is a concrete structural type (implementing the Event interface). This function panics if this is not fulfilled. The same handler function can be registered several times for the same type. It will be called for each registration.
The returned function can be used to unregister the handler again. It is a closure over UnregisterHandler(eType, handlerFunc).
func (*Dispatcher) UnregisterHandler ¶
func (dispatcher *Dispatcher) UnregisterHandler(handlerFunc interface{})
UnregisterHandler removes a handler that was previously registered. If there was no registration done, this call is ignored. If the same handler was registered multiple times, all registrations are removed.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue stores events to be dispatched at a later time.
func (*Queue) Event ¶
Event queues the given event at the tail. When events are dispatched, they are so first-in, first-out (FIFO). nil events are ignored. Typed event pointer that are nil are not ignored.
type Registry ¶ added in v0.3.0
type Registry interface { // RegisterHandler must be called a function that takes one argument which is // a concrete structural type (implementing the Event interface). // This function panics if this is not fulfilled. // The same handler function can be registered several times for the same type. // It will be called for each registration. // // The returned function can be used to unregister the handler again. RegisterHandler(handlerFunc interface{}) func() }
Registry describes an entity where an event handler can be registered.