event

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 0 Imported by: 0

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.

Jump to

Keyboard shortcuts

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