From 8a8610f756a6e17934c0ea5d908edccdffab5ee5 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Tue, 12 Dec 2023 11:50:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20timer.Ticker=20?= =?UTF-8?q?=E7=9A=84=20CronByInstantly=20=E5=87=BD=E6=95=B0=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E6=AD=BB=E9=94=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/timer/ticker.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/utils/timer/ticker.go b/utils/timer/ticker.go index 4b267a3d..18921810 100644 --- a/utils/timer/ticker.go +++ b/utils/timer/ticker.go @@ -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...) }