From 319d6b6db14190799ede4803d8d7a5af487df34f Mon Sep 17 00:00:00 2001 From: Yun Date: Sat, 11 Nov 2023 17:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=AC=E5=85=B1=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- single.go | 11 +++-------- types.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/single.go b/single.go index de079e9..638dc02 100644 --- a/single.go +++ b/single.go @@ -21,13 +21,11 @@ var timerMapMux sync.Mutex var timerCount int // 当前定时数目 var onceLimit sync.Once // 实现单例 -var nextTime = time.Now() // 下一次执行的时间 -type ContextValueKey string // 定义context 传递的Key类型 -const ( - extendParamKey ContextValueKey = "extend_param" -) + + + type single struct{} @@ -182,9 +180,6 @@ func (s *single) iteratorTimer(ctx context.Context, nowTime time.Time) { // fmt.Println("timer: one finish") } -// 定义各个回调函数 -type callback func(ctx context.Context) bool - // 定时器操作类 // 这里不应painc func (s *single) timerAction(ctx context.Context, call callback, uniqueKey string, extend ExtendParams) bool { diff --git a/types.go b/types.go index 2941402..60a186f 100644 --- a/types.go +++ b/types.go @@ -1,6 +1,9 @@ package timer -import "time" +import ( + "context" + "time" +) type timerStr struct { Callback callback // 需要回调的方法 @@ -16,3 +19,12 @@ type timerStr struct { type ExtendParams struct { Params map[string]interface{} // 带出去的参数 } +var nextTime = time.Now() // 下一次执行的时间 + +type ContextValueKey string // 定义context 传递的Key类型 +const ( + extendParamKey ContextValueKey = "extend_param" +) + +// 定义各个回调函数 +type callback func(ctx context.Context) bool