28 lines
380 B
Go
28 lines
380 B
Go
package tools
|
|
|
|
import (
|
|
"runtime/debug"
|
|
|
|
"gitea.ddegame.cn/open/servicebase/pkg/log"
|
|
)
|
|
|
|
func Recover(cleanups ...func()) {
|
|
for _, cleanup := range cleanups {
|
|
cleanup()
|
|
}
|
|
|
|
if p := recover(); p != nil {
|
|
log.ErrorF("occur panic: [%+v], stack info [%s]", p, debug.Stack())
|
|
}
|
|
}
|
|
|
|
func RunSafe(fn func()) {
|
|
defer Recover()
|
|
|
|
fn()
|
|
}
|
|
|
|
func GoSafe(fn func()) {
|
|
go RunSafe(fn)
|
|
}
|