补充异步处理异常捕捉

This commit is contained in:
liwei1dao 2024-01-10 10:05:05 +08:00
parent 1d1150a0fa
commit 1f1dce7e23

View File

@ -7,6 +7,7 @@ import (
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"runtime"
"time"
"go_dreamfactory/lego/sys/log"
@ -983,6 +984,14 @@ func (this *ModuleBase) FormatRes(res []*cfg.Gameatn) (ret []*cfg.Gameatn) {
//异步调用用户处理流
func (this *ModuleBase) AsynHandleSession(session comm.IUserSession, handle func(session comm.IUserSession)) {
defer func() { //程序异常 收集异常信息传递给前端显示
if r := recover(); r != nil {
buf := make([]byte, 4096)
l := runtime.Stack(buf, false)
err := fmt.Errorf("%v: %s", r, buf[:l])
log.Errorf("[AsynHandleSession] err:%s", err.Error())
}
}()
handle(session)
session.Push()
this.PutUserSession(session)