Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SubscribeAny ¶
func SubscribeAny[T any](callback EventHandler[T])
SubscribeAny adds an EventHandler to the list of global EventHandler objects for this a given event data type. When an event is published, the callback will be triggered with the event data. Note: An EventHandler subscribed here will remain throughout program execution. Objects which should be freed from memory should not use this method to avoid memory leaks.
Types ¶
type EventEmitter ¶
type EventEmitter[T any] struct { // contains filtered or unexported fields }
EventEmitter describes a provider which can subscribe EventHandler methods for callback when the event type (generic) is published. It additionally provides methods for publishing events.
func (*EventEmitter[T]) EventType ¶
func (e *EventEmitter[T]) EventType() reflect.Type
EventType returns the event type given an EventEmitter object
func (*EventEmitter[T]) Publish ¶
func (e *EventEmitter[T]) Publish(event T) error
Publish emits the provided event by calling every EventHandler subscribed.
func (*EventEmitter[T]) Subscribe ¶
func (e *EventEmitter[T]) Subscribe(callback EventHandler[T])
Subscribe adds an EventHandler to the list of subscribed EventHandler objects for this emitter. When an event is published, the callback will be triggered with the event data.
type EventHandler ¶
EventHandler defines a function type where its input type is the generic type.
func (*EventHandler[T]) EventType ¶
func (e *EventHandler[T]) EventType() reflect.Type
EventType returns the event type given an EventHandler object