hooks

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package hooks implements the observer pattern

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

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

Hook is a mechanism which supports the ability to dispatch data to arbitrary listener callbacks

func NewHook

func NewHook[T any](db *sql.DB) *Hook[T]

NewHook creates a new Hook

func (*Hook[T]) After

func (h *Hook[T]) After(callback Listener[T])

After registers a callback function to be invoked after the hook action occurs.

func (*Hook[T]) Before

func (h *Hook[T]) Before(callback Listener[T])

Before registers a callback function to be invoked before the hook action occurs.

func (*Hook[T]) Dispatch

func (h *Hook[T]) Dispatch(ctx context.Context, event T, fn func(context.Context) error) error

Dispatch invokes all listeners synchronously within a transaction. The id should uniquely identify the resource that triggers the dispatch.

type Listener

type Listener[T any] func(ctx context.Context, event T) error

Listener is a function that can listen and react to a hook event

Jump to

Keyboard shortcuts

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