-- store global callbacks concurrently
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.
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.