dispatcher

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package dispatcher contains functionality for uni-directional event dispatching

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventDispatcher

type EventDispatcher[ID comparable, E any] interface {
	Dispatch(ID, ...E)
}

An EventDispatcher invokes listeners corresponding to the provided event ID and event objects.

func New

func New[ID comparable, E any](listenerMatcher Matcher[ID, E]) EventDispatcher[ID, E]

New creates an EventDispatcher using the provided matcher.

If nil is provided, an EventDispatcher having no listeners is created

func NewFrom

func NewFrom[ID comparable, E any](
	globalListeners []listener.Listener[ID, E],
	listenerMap listener.Map[ID, E],
) EventDispatcher[ID, E]

NewFrom creates an EventDispatcher using the provided global and event-specific listeners.

Global listeners are always executed no matter what event ID is passed. Listeners triggered by a specific event ID can be specified as a map in the second parameter

Nil can be passed for either parameter to specify that no listeners are present

func NewFromFunc

func NewFromFunc[ID comparable, E any](closure func(ID, E), additional ...func(ID, E)) EventDispatcher[ID, E]

NewFromFunc creates an EventDispatcher using one or more of the provided closures.

Each closure is converted into a global listener -- all will be invoked for each event that's dispatched

func NewFromListener

func NewFromListener[ID comparable, E any](targetListener listener.Listener[ID, E], additional ...listener.Listener[ID, E]) EventDispatcher[ID, E]

NewFromListener creates an EventDispatcher using one or more provided listeners

Each listener is converted into a global listener -- all will be invoked for each event that's dispatched. Note: Nil listeners are not permitted and the function will panic if one is encountered.

func NewFromMap

func NewFromMap[ID comparable, E any](listenerMap map[ID]listener.Listener[ID, E]) EventDispatcher[ID, E]

NewFromMap creates an EventDispatcher where the specified listeners are only triggered for the corresponding event ID they're mapped to.

Each listener is converted into a global listener -- all will be invoked for each event that's dispatched. Note: Nil maps or listeners are not permitted and the function will panic if one is encountered.

type Matcher

type Matcher[ID comparable, E any] interface {
	Match(ID) []listener.Listener[ID, E]
}

A Matcher identifies relevant listeners for the given event ID, returning them as a slice.

Jump to

Keyboard shortcuts

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