Documentation
¶
Overview ¶
Package events contains a manager for dispatching and receiving arbitrary events.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event interface { proto.Message GetTime() *timestamppb.Timestamp GetMessage() string }
An Event is any protobuf message that has a time and message.
type EventSinkHandle ¶
type EventSinkHandle string
An EventSinkHandle is a reference to a registered EventSink so that it can be unregistered.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
A Manager manages the dispatching of events to event sinks.
func (*Manager) Register ¶
func (mgr *Manager) Register(sink EventSink) (handle EventSinkHandle)
Register registers an event sink to receive events.
func (*Manager) Unregister ¶
func (mgr *Manager) Unregister(sinkHandle EventSinkHandle)
Unregister unregisters an event sink so it no longer receives events.
type Target ¶ added in v0.24.0
type Target[T any] struct { // contains filtered or unexported fields }
A Target is a target for events.
Listeners are added with AddListener with a function to be called when the event occurs. AddListener returns a Handle which can be used to remove a listener with RemoveListener.
Dispatch dispatches events to all the registered listeners.
Target is safe to use in its zero state.
Each listener is run in its own goroutine.
A slow listener will cause the next event dispatch to block. This is the opposite behavior from Manager.
Close will remove and cancel all listeners.
func (*Target[T]) AddListener ¶ added in v0.24.0
AddListener adds a listener to the target.
func (*Target[T]) Close ¶ added in v0.24.0
func (t *Target[T]) Close()
Close closes the event target. This can be called multiple times safely.
func (*Target[T]) RemoveListener ¶ added in v0.24.0
func (t *Target[T]) RemoveListener(handle Handle)
RemoveListener removes a listener from the target.