``` feat(pet): 重构宠物繁殖系统,添加蛋孵化功能

This commit is contained in:
1
2026-01-20 22:08:36 +00:00
parent cf4660fbe0
commit 5ef922278a
68 changed files with 4467 additions and 584 deletions

View File

@@ -0,0 +1,53 @@
// Copyright 2020-2024 guonaihong, antlabs. All rights reserved.
//
// mit license
package timer
import "time"
type Next interface {
Next(time.Time) time.Time
}
// 定时器接口
type Timer interface {
// 一次性定时器
AfterFunc(expire time.Duration, callback func()) TimeNoder
// 周期性定时器
ScheduleFunc(expire time.Duration, callback func()) TimeNoder
// 自定义下次的时间
CustomFunc(n Next, callback func()) TimeNoder
// 运行
Run()
// 停止所有定时器
Stop()
}
// 停止单个定时器
type TimeNoder interface {
Stop() bool
// 重置时间器
Reset(expire time.Duration) bool
}
// 定时器构造函数
func NewTimer(opt ...Option) Timer {
var o option
for _, cb := range opt {
cb(&o)
}
if o.timeWheel {
return newTimeWheel()
}
if o.minHeap {
return newMinHeap()
}
return newTimeWheel()
}