update
This commit is contained in:
22
common.go
Normal file
22
common.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package mycommon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.makemake.in/kzkzzzz/mycommon/mylog"
|
||||||
|
"runtime/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SafeFn(fn func()) {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
mylog.Errorf("panic: %s\n%s", err, string(debug.Stack()))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
fn()
|
||||||
|
}
|
||||||
|
|
||||||
|
func SafeGo(fn func()) {
|
||||||
|
go func() {
|
||||||
|
SafeFn(fn)
|
||||||
|
}()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user