Documentation ¶
Index ¶
- type Event
- func (e *Event[T]) Fire(ctx context.Context, event T) error
- func (e *Event[T]) ListenerCount() int
- func (e *Event[T]) On(listener func(ctx context.Context, event T) error) (unsubscribe func())
- func (e *Event[T]) Once(listener func(ctx context.Context, event T) error)
- func (e *Event[T]) Prepend(listener func(ctx context.Context, event T) error) (unsubscribe func())
- func (e *Event[T]) PrependOnce(listener func(ctx context.Context, event T) error)
- func (e *Event[T]) RemoveAllListeners()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event[T any] struct { // contains filtered or unexported fields }
Event is a generic event system.
func (*Event[T]) Fire ¶
Fire fires the event to all listeners synchronously. All registered listeners will be copied before actually being called, so that it is safe to add or remove listeners within listener callbacks.
func (*Event[T]) ListenerCount ¶
ListenerCount returns the number of listeners for a given event.
func (*Event[T]) Once ¶
Once subscribes the listener to the dispatcher and unsubscribe the listener once after the event is processed by the listener.
func (*Event[T]) Prepend ¶
Prepend adds the listener to the beginning of the listeners queue for the topic it listens to. The listeners will not be deduplicated. If subscribed more than once, the event will be added and processed more than once.
func (*Event[T]) PrependOnce ¶
PrependOnce adds a one-time listener function for the event it listens to, at the top of the listener queue waiting for the same event. The listener will be unsubscribed once after the event is processed by the listener .
func (*Event[T]) RemoveAllListeners ¶
func (e *Event[T]) RemoveAllListeners()
RemoveAllListeners removes all listeners for a given event.