From 0c770b805d554331272303883acd02810733ce48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 29 May 2025 18:56:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core.go b/core.go index 526b21b..7a1de66 100644 --- a/core.go +++ b/core.go @@ -244,13 +244,13 @@ func (tw *TimeWheel) getPosAndCircleByInterval(d time.Duration) (int, int) { // Date : 13:47 2023/8/4 func (tw *TimeWheel) getPosAndCircleByCreatedTime(createdTime time.Time, d time.Duration, key any) (int, int) { - passedTime := time.Since(createdTime) - passedSeconds := int(passedTime.Seconds()) - delaySeconds := int(d.Seconds()) - intervalSeconds := int(tw.interval.Seconds()) + passedTime := time.Since(createdTime) // 计算从创建时间到现在经过了多少时间 + passedSeconds := int(passedTime.Seconds()) // 从开始到现在经历的秒数 + delaySeconds := int(d.Seconds()) // 多久之后执行 + intervalSeconds := int(tw.interval.Seconds()) // 时间轮盘的间隔秒数 - circle := delaySeconds / intervalSeconds / tw.slotCount - pos := (tw.currentPosition + (delaySeconds-(passedSeconds%delaySeconds))/intervalSeconds) % tw.slotCount + circle := delaySeconds / intervalSeconds / tw.slotCount // 计算需要走多少圈 + pos := (tw.currentPosition + (delaySeconds-(passedSeconds%delaySeconds))/intervalSeconds) % tw.slotCount // 计算下次执行的位置 // 特殊case,当计算的位置和当前位置重叠时,因为当前位置已经走过了,所以circle需要减一 if pos == tw.currentPosition && circle != 0 {