MCPcopy
hub / github.com/pocketbase/pocketbase / FireAndForget

Function FireAndForget

tools/routine/routine.go:13–35  ·  view source on GitHub ↗

FireAndForget executes f() in a new go routine and auto recovers if panic. **Note:** Use this only if you are not interested in the result of f() and don't want to block the parent go routine.

(f func(), wg ...*sync.WaitGroup)

Source from the content-addressed store, hash-verified

11// **Note:** Use this only if you are not interested in the result of f()
12// and don't want to block the parent go routine.
13func FireAndForget(f func(), wg ...*sync.WaitGroup) {
14 if len(wg) > 0 && wg[0] != nil {
15 wg[0].Add(1)
16 }
17
18 go func() {
19 if len(wg) > 0 && wg[0] != nil {
20 defer wg[0].Done()
21 }
22
23 defer func() {
24 if err := recover(); err != nil {
25 log.Println("[FireAndForget] RECOVERED FROM PANIC:", err)
26
27 stack := make([]byte, 2<<10) // 2 KB
28 length := runtime.Stack(stack, false)
29 log.Println(string(stack[:length]))
30 }
31 }()
32
33 f()
34 }()
35}

Callers 14

NewWithConfigFunction · 0.92
runDueMethod · 0.92
TestFireAndForgetFunction · 0.92
registerBaseHooksMethod · 0.92
backupRestoreFunction · 0.92
logRequestFunction · 0.92
authAlertFunction · 0.92
recordRequestOTPFunction · 0.92
realtimeBroadcastRecordFunction · 0.92
ServeFunction · 0.92

Calls 2

fFunction · 0.50
AddMethod · 0.45

Tested by 1

TestFireAndForgetFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…