event

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: GPL-3.0 Imports: 0 Imported by: 4

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 interface {
	// Close removes the event handler this cookie is for.
	Close()
}

A cookie is returned when you add an event handler so you can remove it later if you so choose.

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 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()

Jump to

Keyboard shortcuts

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