github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/result/fallback.go (about) 1 package result 2 3 // Go a function with recover and do nothing. 4 func Go(fn func()) { 5 SafeGo(fn, nil) 6 } 7 8 // SafeGo a function with recover and do callback. 9 func SafeGo(fn func(), handle func(x interface{})) { 10 defer func() { 11 if x := recover(); x != nil { 12 if handle != nil { 13 handle(x) 14 } 15 } 16 }() 17 fn() 18 }