slotCount和interval增加默认值

This commit is contained in:
白茶清欢 2023-08-11 18:18:00 +08:00
parent d6b415a839
commit 4d9cb375ec

View File

@ -21,6 +21,14 @@ import (
// //
// Date : 16:50 2023/8/11 // Date : 16:50 2023/8/11
func NewTimeWheel(slotCount int, interval time.Duration) *TimeWheel { func NewTimeWheel(slotCount int, interval time.Duration) *TimeWheel {
if slotCount <= 0 {
// 默认100个槽位
slotCount = 100
}
if interval.Seconds() == 0 {
// 默认60s扫描一次
interval = time.Second * 60
}
tw := &TimeWheel{ tw := &TimeWheel{
Interval: interval, Interval: interval,
Slots: make([]*list.List, slotCount), Slots: make([]*list.List, slotCount),