You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
auth2/internal/util/goroutine.go

23 lines
343 B
Go

package util
import (
"runtime/debug"
"go-micro.dev/v4/logger"
)
// GoSafe will run func in goroutine safely, avoid crash from unexpected panic
func GoSafe(fn func()) {
if fn == nil {
return
}
go func() {
defer func() {
if e := recover(); e != nil {
logger.Errorf("[panic]%v\n%s", e, debug.Stack())
}
}()
fn()
}()
}