dispatcher

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: AGPL-3.0 Imports: 7 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 struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) (*Dispatcher, error)

New creates a new event service

func (*Dispatcher) Broadcast

func (d *Dispatcher) Broadcast(ctx context.Context, params ...interface{}) error

Broadcast fires an event to all listeners

func (*Dispatcher) Close

func (d *Dispatcher) Close() error

Close closes the event service

func (*Dispatcher) CountListeners

func (d *Dispatcher) CountListeners(eventName string) int

CountListeners returns the number of listeners for an event

func (*Dispatcher) EmitEvent

func (d *Dispatcher) EmitEvent(ctx context.Context, name string, params ...interface{}) (err error)

EmitEvent fires an event

func (*Dispatcher) EventExists

func (d *Dispatcher) EventExists(name string) bool

EventExists checks if an event exists

func (*Dispatcher) FilterEvents

func (d *Dispatcher) FilterEvents(filterFunc func(string, []types.EventListener) bool) []string

FilterEvents returns a list of events filtered by a filter function

func (*Dispatcher) ListEvents

func (d *Dispatcher) ListEvents() []string

ListEvents returns a list of all events

func (*Dispatcher) Subscribe

func (d *Dispatcher) Subscribe(ctx context.Context, name string, fn interface{}, maxTrigger int) (context.CancelFunc, error)

Subscribe registers a listener for an event with optional max call limit

type Option

type Option func(*Options)

func WithLogger

func WithLogger(logger logger.Logger) Option

WithLogger sets the logger on the Options struct.

type Options

type Options struct {
	Logger logger.Logger
}

Jump to

Keyboard shortcuts

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