Compare commits
No commits in common. "main" and "v1.0.2" have entirely different histories.
@ -13,6 +13,7 @@ type taskSlice struct {
|
||||
rawCycle int
|
||||
mode TimeMode
|
||||
task func()
|
||||
tiny bool
|
||||
}
|
||||
|
||||
type TimeWheel struct {
|
||||
@ -76,6 +77,7 @@ func (t *TimeWheel) AddTask(id string, mode TimeMode, task func(), flower time.D
|
||||
mode: mode,
|
||||
rawCycle: cycle,
|
||||
pos: pos,
|
||||
tiny: int(flower) < t.slotLen*int(t.interval),
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,8 +164,8 @@ func (t *TimeWheel) addTask(task *taskSlice) {
|
||||
}
|
||||
|
||||
var list *list.List
|
||||
if task.mode == TimeTypeLoop {
|
||||
task.cycle = task.cycle*t.slotLen + (task.pos-t.curtSlot+t.slotLen)%t.slotLen
|
||||
if task.tiny {
|
||||
task.cycle = (task.pos - t.curtSlot + t.slotLen) % t.slotLen
|
||||
task.rawCycle = task.cycle
|
||||
|
||||
list = t.tinyWheel
|
||||
@ -185,7 +187,7 @@ func (t *TimeWheel) removeTask(key string) {
|
||||
|
||||
task := etask.Value.(*taskSlice)
|
||||
|
||||
if task.mode == TimeTypeLoop {
|
||||
if task.tiny {
|
||||
_ = t.tinyWheel.Remove(etask)
|
||||
} else {
|
||||
_ = t.slots[task.pos].Remove(etask)
|
||||
|
@ -11,8 +11,7 @@ func Test_timeWheel(t *testing.T) {
|
||||
|
||||
<-time.After(10 * time.Millisecond)
|
||||
|
||||
t.Errorf("start time, %v", time.Now())
|
||||
|
||||
t.Errorf("test2, %v", time.Now())
|
||||
timeWheel.AddTask("test1", TimeTypeLoop, func() {
|
||||
t.Errorf("test1, %v", time.Now())
|
||||
}, time.Millisecond*300)
|
||||
@ -23,5 +22,5 @@ func Test_timeWheel(t *testing.T) {
|
||||
t.Errorf("test2, %v", time.Now())
|
||||
}, time.Second)
|
||||
|
||||
<-time.After(8 * time.Second)
|
||||
<-time.After(6 * time.Second)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user