Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher[E any] struct { // contains filtered or unexported fields }
Dispatcher is a generic event dispatcher. It maintains a mapping of unique indexes to subscribers, which are channels that events are sent to.
func NewDispatcher ¶
func NewDispatcher[E any]() *Dispatcher[E]
NewDispatcher creates a new Dispatcher.
func (*Dispatcher[E]) Dispatch ¶
func (d *Dispatcher[E]) Dispatch(event E)
Dispatch sends an event to all subscribers.
func (*Dispatcher[E]) Subscribe ¶
func (d *Dispatcher[E]) Subscribe(subscriber chan E) int
Subscribe adds a new subscriber to the Dispatcher. The subscriber is a channel on which events will be sent to. Returns the unique index of the subscriber.
func (*Dispatcher[E]) Unsubscribe ¶
func (d *Dispatcher[E]) Unsubscribe(index int)
Unsubscribe removes a subscriber from the Dispatcher at the given unique index.
Click to show internal directories.
Click to hide internal directories.