hook

package
v0.0.0-...-b5db161 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStopPropagation = errors.New("event hook propagation stopped")

Functions

This section is empty.

Types

type Handler

type Handler[T any] func(e T) error

type Hook

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

Event hooks store

concurrent safe structure, aka. callbacks propagation

func (*Hook[T]) Add

func (h *Hook[T]) Add(fn Handler[T]) string

Append a handler to the hook

func (*Hook[T]) PreAdd

func (h *Hook[T]) PreAdd(fn Handler[T]) string

Prepend a handler to the hook

func (*Hook[T]) Remove

func (h *Hook[T]) Remove(id string)

Remove a single hook handler by its id

func (*Hook[T]) RemoveAll

func (h *Hook[T]) RemoveAll()

Remove all registered handlers

func (*Hook[T]) Trigger

func (h *Hook[T]) Trigger(data T, oneOffHandlers ...Handler[T]) error

Trigger executes all registered hook handlers one by one with the specified `data` as an argument

Optionally, this method allows also to register additional one off handlers that will be temporary appended to the handlers queue

The execution stops when: - hook.ErrStopPropagation is returned in one of the handlers - any non-nil error is returned in one of the handlers

Jump to

Keyboard shortcuts

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