Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher[T any] interface { // Dispatch broadcasts the T event to any subscribed listeners asynchronously. Dispatch(event T) // DispatchSync is a special dispatch scenario which will block if any // listeners are not yet receiving events. This should be used if you // need to guarantee that all receivers are processing events before // continuing. DispatchSync(event T) // AddEventHandler adds a new event handler method that is called whenever an event T is dispatched. A // unique HandlerID is returned that can be used to remove the handler. AddEventHandler(handler EventHandler[T]) HandlerID // RemoveEventHandler removes an event handler that was added via AddEventHandler using it's HandlerID. // Returns true if the handler was successfully removed. RemoveEventHandler(id HandlerID) bool // NewEventStream returns an asynchronous event stream that can be used to receive dispatched events. NewEventStream() EventStream[T] }
Dispatcher[T] is an implementation prototype for an object capable of dispatching T instances to any subscribed listeners.
func DispatcherFor ¶
func DispatcherFor[T any]() Dispatcher[T]
DispatcherFor[T] locates an existing global dispatcher for an event type, or creates a new one if one does not exist
type EventHandler ¶
type EventHandler[T any] func(T)
EventHandler[T] is a type used to receive events from a dispatcher.
type EventStream ¶
type EventStream[T any] interface { // Stream returns access to the event T channel where events will arrive. Stream() <-chan T // Close shuts down the event stream, closing the channel Close() // IsClosed is set to true if the event stream has been closed IsClosed() bool }
EventStream[T] is an implementation prototype for an object capable of asynchronously listening for events dispatched via Dispatcher[T] implementation.
Click to show internal directories.
Click to hide internal directories.