This commit is contained in:
meixiongfeng 2023-07-13 11:49:52 +08:00
commit 5d302312b2
3 changed files with 21 additions and 23 deletions

View File

@ -2,8 +2,8 @@ package timewheel
import ( import (
"context" "context"
"go_dreamfactory/lego"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"runtime"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -185,10 +185,10 @@ func (this *TimeWheel) handleTick() {
} }
if task.async { if task.async {
go func(task *Task) { go func(_task *Task) {
go this.calltask(task, task.args...) this.calltask(_task, _task.args...)
this.collectTask(_task)
}(task) }(task)
} else { } else {
// optimize gopool // optimize gopool
this.calltask(task, task.args...) this.calltask(task, task.args...)
@ -200,10 +200,10 @@ func (this *TimeWheel) handleTick() {
this.putCircle(task, modeIsCircle) this.putCircle(task, modeIsCircle)
continue continue
} }
if !task.async { //异步模式下不能清理
// gc
this.collectTask(task) this.collectTask(task)
} }
}
if this.currentIndex == this.bucketsNum-1 { if this.currentIndex == this.bucketsNum-1 {
this.currentIndex = 0 this.currentIndex = 0
@ -215,13 +215,11 @@ func (this *TimeWheel) handleTick() {
// 执行时间轮事件 捕捉异常错误 防止程序崩溃 // 执行时间轮事件 捕捉异常错误 防止程序崩溃
func (this *TimeWheel) calltask(task *Task, args ...interface{}) { func (this *TimeWheel) calltask(task *Task, args ...interface{}) {
defer func() { //程序异常 收集异常信息传递给前端显示 defer lego.Recover("TimeWheel")
if r := recover(); r != nil { if task.callback == nil {
buf := make([]byte, 4096) log.Error("sys.timeWheel task callback err!", log.Field{Key: "task", Value: task})
l := runtime.Stack(buf, false) return
log.Errorf("timewheel err:%s", string(buf[0:l]))
} }
}()
task.callback(task, task.args...) task.callback(task, task.args...)
} }

View File

@ -153,7 +153,7 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (e
return return
} }
event.TriggerEvent(comm.EventFriendChange, uid, len(self.FriendIds)) event.TriggerEvent(comm.EventFriendChange, uid, int32(len(self.FriendIds)))
} }
// 拥有xx个好友 // 拥有xx个好友