renamed Trigger arg to avoid confusion with the Handler type

This commit is contained in:
Gani Georgiev 2024-10-07 09:59:10 +03:00
parent 393b461ea2
commit 1e480c5380
1 changed files with 4 additions and 4 deletions

View File

@ -145,16 +145,16 @@ func (h *Hook[T]) Length() int {
// with the specified event as an argument. // with the specified event as an argument.
// //
// Optionally, this method allows also to register additional one off // Optionally, this method allows also to register additional one off
// handlers that will be temporary appended to the handlers queue. // handler funcs that will be temporary appended to the handlers queue.
// //
// NB! Each hook handler must call event.Next() in order the hook chain to proceed. // NB! Each hook handler must call event.Next() in order the hook chain to proceed.
func (h *Hook[T]) Trigger(event T, oneOffHandlers ...func(T) error) error { func (h *Hook[T]) Trigger(event T, oneOffHandlerFuncs ...func(T) error) error {
h.mu.RLock() h.mu.RLock()
handlers := make([]func(T) error, 0, len(h.handlers)+len(oneOffHandlers)) handlers := make([]func(T) error, 0, len(h.handlers)+len(oneOffHandlerFuncs))
for _, handler := range h.handlers { for _, handler := range h.handlers {
handlers = append(handlers, handler.Func) handlers = append(handlers, handler.Func)
} }
handlers = append(handlers, oneOffHandlers...) handlers = append(handlers, oneOffHandlerFuncs...)
h.mu.RUnlock() h.mu.RUnlock()
event.setNextFunc(nil) // reset in case the event is being reused event.setNextFunc(nil) // reset in case the event is being reused