callback

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action[T any] func(*Event[T])

type Callback

type Callback[T any] struct {
	Action  Action[T]
	Enabled bool
}

Callback contains the function reference and parameters.

func (*Callback[T]) Call

func (c *Callback[T]) Call(v T)

Call constructs an Event object and passes them to the internal Action function.

type Event

type Event[T any] struct {
	Data     T
	Callback *Callback[T]
}

Event contains the content and reference to the Callback struct.

type Manager

type Manager[T any] struct {
	// contains filtered or unexported fields
}

Manager manages the lifecycle of a collection of generic Callback structs.

func NewManager

func NewManager[T any]() *Manager[T]

NewManager constructs a new Manager structs.

func (*Manager[T]) Call

func (m *Manager[T]) Call(v T)

Call fans out Event objects across all callbacks in the map.

func (*Manager[T]) Deregister

func (m *Manager[T]) Deregister(c *Callback[T]) *Callback[T]

Reregister removes a Callback struct from the map.

func (*Manager[T]) Map

func (m *Manager[T]) Map() map[*Callback[T]]bool

Map returns a clone of the internal Callback map.

func (*Manager[T]) Once

func (m *Manager[T]) Once(action Action[T]) *Callback[T]

Once adds a Callback to the map that is deregistered after first execution.

func (*Manager[T]) Recurring

func (m *Manager[T]) Recurring(action Action[T]) *Callback[T]

Recurring adds a recurring Callback struct to the map.

func (*Manager[T]) Register

func (m *Manager[T]) Register(c *Callback[T]) *Callback[T]

Register adds a Callback struct to the map.

func (*Manager[T]) Reset

func (m *Manager[T]) Reset()

Reset clears all Callback struct from the map.

func (*Manager[T]) SleepUntilDisabled

func (m *Manager[T]) SleepUntilDisabled(action Action[T]) *Callback[T]

SleepUntilDisabled adds a Callback struct to the map and pauses the current goroutine until the callback is disabled.

Jump to

Keyboard shortcuts

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