MCPcopy
hub / github.com/pocketbase/pocketbase / Trigger

Method Trigger

tools/hook/hook.go:153–174  ·  view source on GitHub ↗

Trigger executes all registered hook handlers one by one with the specified event as an argument. Optionally, this method allows also to register additional one off handler funcs that will be temporary appended to the handlers queue. NB! Each hook handler must call event.Next() in order the hook c

(event T, oneOffHandlerFuncs ...func(T) error)

Source from the content-addressed store, hash-verified

151//
152// NB! Each hook handler must call event.Next() in order the hook chain to proceed.
153func (h *Hook[T]) Trigger(event T, oneOffHandlerFuncs ...func(T) error) error {
154 h.mu.RLock()
155 handlers := make([]func(T) error, 0, len(h.handlers)+len(oneOffHandlerFuncs))
156 for _, handler := range h.handlers {
157 handlers = append(handlers, handler.Func)
158 }
159 handlers = append(handlers, oneOffHandlerFuncs...)
160 h.mu.RUnlock()
161
162 event.setNextFunc(nil) // reset in case the event is being reused
163
164 for i := len(handlers) - 1; i >= 0; i-- {
165 i := i
166 old := event.nextFunc()
167 event.setNextFunc(func() error {
168 event.setNextFunc(old)
169 return handlers[i](event)
170 })
171 }
172
173 return event.Next()
174}
175
176func generateHookId() string {
177 return security.PseudorandomString(20)

Callers 15

loadMuxMethod · 0.95
ExecuteMethod · 0.80
SendMethod · 0.80
SendMethod · 0.80
TestHookAddHandlerAndAddFunction · 0.80
TestHookUnbindFunction · 0.80
TestTaggedHookFunction · 0.80
SendRecordAuthAlertFunction · 0.80
SendRecordOTPFunction · 0.80
SendRecordPasswordResetFunction · 0.80
SendRecordVerificationFunction · 0.80

Calls 3

setNextFuncMethod · 0.65
nextFuncMethod · 0.65
NextMethod · 0.65