events

package
v0.13.1-beta1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 2 Imported by: 4

Documentation

Index

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

func (e *Event[T]) Fire(ctx context.Context, event T) error

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

func (e *Event[T]) ListenerCount() int

ListenerCount returns the number of listeners for a given event.

func (*Event[T]) On

func (e *Event[T]) On(listener func(ctx context.Context, event T) error) (unsubscribe func())

On registers a listener to the event at the bottom of the listener queue.

func (*Event[T]) Once

func (e *Event[T]) Once(listener func(ctx context.Context, event T) error)

Once subscribes the listener to the dispatcher and unsubscribe the listener once after the event is processed by the listener.

func (*Event[T]) Prepend

func (e *Event[T]) Prepend(listener func(ctx context.Context, event T) error) (unsubscribe func())

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

func (e *Event[T]) PrependOnce(listener func(ctx context.Context, event T) error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL