diff --git a/min_heap_node.go b/min_heap_node.go index 760d645..939e690 100644 --- a/min_heap_node.go +++ b/min_heap_node.go @@ -17,11 +17,13 @@ type minHeapNode struct { isSchedule bool // 是否是周期性任务 } -func (m *minHeapNode) Stop() { +func (m *minHeapNode) Stop() bool { m.root.removeTimeNode(m) + return true } -func (m *minHeapNode) Reset(d time.Duration) { +func (m *minHeapNode) Reset(d time.Duration) bool { m.root.resetTimeNode(m, d) + return true } func (m *minHeapNode) Next(now time.Time) time.Time { diff --git a/time_wheel_node.go b/time_wheel_node.go index 55e33c9..4986a83 100644 --- a/time_wheel_node.go +++ b/time_wheel_node.go @@ -76,7 +76,7 @@ type timeNode struct { // // 1和3.1状态是没有问题的 // 2和3.2状态会是没有锁保护下的操作,会有数据竞争 -func (t *timeNode) Stop() { +func (t *timeNode) Stop() bool { atomic.StoreUint32(&t.stop, haveStop) @@ -87,14 +87,15 @@ func (t *timeNode) Stop() { cpyList.Lock() defer cpyList.Unlock() if atomic.LoadUint64(&t.version) != atomic.LoadUint64(&cpyList.version) { - return + return false } cpyList.Del(&t.Head) + return true } // warning: 该函数目前没有稳定 -func (t *timeNode) Reset(expire time.Duration) { +func (t *timeNode) Reset(expire time.Duration) bool { cpyList := (*Time)(atomic.LoadPointer(&t.list)) cpyList.Lock() defer cpyList.Unlock() @@ -109,4 +110,5 @@ func (t *timeNode) Reset(expire time.Duration) { t.expire = uint64(expire) t.root.add(t, jiffies) + return true } diff --git a/timer.go b/timer.go index f36d622..9dc952c 100644 --- a/timer.go +++ b/timer.go @@ -29,9 +29,9 @@ type Timer interface { // 停止单个定时器 type TimeNoder interface { - Stop() + Stop() bool // 重置时间器 - Reset(expire time.Duration) + Reset(expire time.Duration) bool } // 定时器构造函数