events

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SubscribeAny

func SubscribeAny[T any](callback EventHandler[T])

SubscribeAny adds an EventHandler to the list of global EventHandler objects for this a given event data type. When an event is published, the callback will be triggered with the event data. Note: An EventHandler subscribed here will remain throughout program execution. Objects which should be freed from memory should not use this method to avoid memory leaks.

Types

type EventEmitter

type EventEmitter[T any] struct {
	// contains filtered or unexported fields
}

EventEmitter describes a provider which can subscribe EventHandler methods for callback when the event type (generic) is published. It additionally provides methods for publishing events.

func (*EventEmitter[T]) EventType

func (e *EventEmitter[T]) EventType() reflect.Type

EventType returns the event type given an EventEmitter object

func (*EventEmitter[T]) Publish

func (e *EventEmitter[T]) Publish(event T) error

Publish emits the provided event by calling every EventHandler subscribed.

func (*EventEmitter[T]) Subscribe

func (e *EventEmitter[T]) Subscribe(callback EventHandler[T])

Subscribe adds an EventHandler to the list of subscribed EventHandler objects for this emitter. When an event is published, the callback will be triggered with the event data.

type EventHandler

type EventHandler[T any] func(T) error

EventHandler defines a function type where its input type is the generic type.

func (*EventHandler[T]) EventType

func (e *EventHandler[T]) EventType() reflect.Type

EventType returns the event type given an EventHandler object

Jump to

Keyboard shortcuts

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