event

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: GPL-3.0 Imports: 2 Imported by: 7

Documentation

Overview

Package event provides a system for broadcasting events to multiple event handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

type Broadcaster[L any] struct {
	// contains filtered or unexported fields
}

Broadcaster manages event listeners.

func (*Broadcaster[L]) Connect

func (broadcaster *Broadcaster[L]) Connect(listener L) Cookie

Connect adds a new listener to the broadcaster and returns a corresponding Cookie.

func (*Broadcaster[L]) Listeners added in v0.6.0

func (broadcaster *Broadcaster[L]) Listeners() map[int]L

Listeners returns a map of all connected listeners.

type Cookie io.Closer

Cookie is returned when you add an event handler so you can remove it later if you so choose. When the Close behavior is called, the handler must be removed, even if an error is returned.

func MultiCookie added in v0.19.0

func MultiCookie(cookies ...Cookie) Cookie

MultiCookie creates a single cookie that, when closed, closes a list of other cookies.

type FuncBroadcaster added in v0.6.0

type FuncBroadcaster struct {
	Broadcaster[func()]
}

FuncBroadcaster is a Broadcaster that manages functions with no arguments.

func (*FuncBroadcaster) Broadcast added in v0.6.0

func (broadcaster *FuncBroadcaster) Broadcast()

Broadcast calls all connected listener funcs.

type FuncCookie added in v0.47.0

type FuncCookie func() error

FuncCookie is a cookie that calls a function (itself) when closed.

func (FuncCookie) Close added in v0.47.0

func (cookie FuncCookie) Close() error

type NoCookie added in v0.21.0

type NoCookie struct{}

NoCookie is a cookie that does nothing when closed.

func (NoCookie) Close added in v0.21.0

func (NoCookie) Close() error

Jump to

Keyboard shortcuts

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