Documentation ¶
Overview ¶
GoMit provides facilities for defining, emitting, and handling events within a Go service.
Core principles:
1. Speed over abstraction 2. No order guarantees 3. No persistence
Example ¶
event_controller := new(EventController) /* type Widget struct { EventCount int } func (w *Widget) HandleGomitEvent(e Event) { w.EventCount++ } */ widget := new(Widget) event_controller.RegisterHandler("widget1", widget) event_controller.Emit(new(RandomEventBody)) event_controller.Emit(new(RandomEventBody)) event_controller.Emit(new(RandomEventBody)) time.Sleep(time.Millisecond * 100) fmt.Println(widget.EventCount)
Output: 3
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Delegator ¶
type Delegator interface { RegisterHandler(string, Handler) error UnregisterHandler(string) error IsHandlerRegistered(string) bool HandlerCount() int }
Represents something that takes Handler registrations and unregistrations and delegates event to handlers
type Event ¶
type Event struct { Header EventHeader Body EventBody }
Represents an event emitted by an Emitter and handled by a Handler
type EventBody ¶
type EventBody interface {
Namespace() string
}
Represents the compatible event body provided by the producer.
type EventController ¶
type EventController struct { Handlers map[string]Handler // contains filtered or unexported fields }
Takes registration and unregistration of Handlers and emits Events to be handled by the Handlers.
func NewEventController ¶
func NewEventController() *EventController
initializes an EventController with Handlers
func (*EventController) Emit ¶
func (e *EventController) Emit(b EventBody) (int, error)
Emits an Event from the EventController. Takes an EventBody which is used to build an Event. Returns number of handlers that received the event and error if an error was raised.
func (*EventController) HandlerCount ¶
func (e *EventController) HandlerCount() int
Return count (int) of Handlers
func (*EventController) IsHandlerRegistered ¶
func (e *EventController) IsHandlerRegistered(n string) bool
Returns bool on whether the Handler is registered with this EventController.
func (*EventController) RegisterHandler ¶
func (e *EventController) RegisterHandler(n string, h Handler) error
Registers Handler with the EventController. Takes a string for the unique name(key) and the handler that conforms the to Handler interface. The name(key) is used to unregister or check if registered.
func (*EventController) UnregisterHandler ¶
func (e *EventController) UnregisterHandler(n string) error
Unregisters Handler from the EventController. This is idempotent where if a Handler is not registered no error is returned.
type EventHeader ¶
Contains common data across all Event instances.