hooks

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: BSD-3-Clause Imports: 1 Imported by: 3

README

Hooks

-- store global callbacks concurrently

GoDoc Go Report Card License

Hooks is a package that implements a global repository of callbacks called hooks, which are functions that take an array of empty interface values and do not return anything. Every hook has a fixed integer number, which must be attributed by the user of the package. Adding a function returns an integer ID for that function that can be used to remove it later. This might seem redundant and makes the package slower, but it is a requirement for the use it is intended for. The package is thread safe.

Usage

Add(hook int, f func(a []interface{})) int

Add a callback for hook and return a numerical ID for the function that was added.

Exec(hook int, args ...interface{})

Execute all functions for the hook if there are any, in the order LIFO - last added hook function is executed first, then the second last, and so on.

Remove(hook, id int)

Remove the function with given ID from the hook.

RemoveAll(hook int)

Remove all functions for the hook.

Active(id int) bool

Returns true if one or more functions for the hook are set and the hook is not suspended, false otherwise. Using this function to check first may be more efficient than calling Exec directly, because of the arguments that Exec takes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Active

func Active(hook int) bool

Active returns true if the hook is set, false otherwise. Using this first before using Exec may be more efficient due to the arguments provided to Exec.

func Add

func Add(hook int, f func(a []interface{})) int

Add a function for the given hook. The function is added to the list of functions of the hook. Add returns an ID2 that represents the individual function of the hook.

func Exec

func Exec(hook int, args ...interface{})

Exec executes all functions for the hook with the given args. It does nothing if there is no function for the hook. The functions for a hook are executed in LIFO order. While functions for a hook are executed, the hook itself is not called.

func Remove

func Remove(hook, id int)

Remove the function with ID for the given hook, if it exists.

func RemoveAll

func RemoveAll(hook int)

Remove all functions for the hook.

Types

type HookContainer added in v0.0.2

type HookContainer struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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