添加注释

This commit is contained in:
白茶清欢 2025-05-29 18:56:49 +08:00
parent 029c268af6
commit 0c770b805d

12
core.go
View File

@ -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 {