Skip to content

Commit

Permalink
fix: 修复 timer.Ticker 的 CronByInstantly 函数导致的死锁问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Dec 12, 2023
1 parent 5714a43 commit 8a8610f
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions utils/timer/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,23 @@ func (slf *Ticker) Cron(name, expression string, handleFunc interface{}, args ..

// CronByInstantly 与 Cron 相同,但是会立即执行一次
func (slf *Ticker) CronByInstantly(name, expression string, handleFunc interface{}, args ...interface{}) {
var values = make([]reflect.Value, len(args))
for i, v := range args {
values[i] = reflect.ValueOf(v)
}
f := reflect.ValueOf(handleFunc)
slf.lock.RLock()
defer slf.lock.RUnlock()
if slf.handle != nil {
slf.handle(name, func() {
func(name, expression string, handleFunc interface{}, args ...interface{}) {
var values = make([]reflect.Value, len(args))
for i, v := range args {
values[i] = reflect.ValueOf(v)
}
f := reflect.ValueOf(handleFunc)
slf.lock.RLock()
defer slf.lock.RUnlock()
if slf.handle != nil {
slf.handle(name, func() {
f.Call(values)
})
} else {
f.Call(values)
})
} else {
f.Call(values)
}
}
}(name, expression, handleFunc, args...)

slf.Cron(name, expression, handleFunc, args...)
}

Expand Down

0 comments on commit 8a8610f

Please sign in to comment.