优化延时队列及队列集合的逻辑

This commit is contained in:
fantasticbin 2024-12-10 08:10:08 +08:00
parent 800c590a3a
commit f36180bc8a

View File

@ -26,11 +26,11 @@ func (q *DelayLkQueue[TKey, TValue]) DelayEnqueue(value TValue, duration time.Du
// CancellableDelayEnqueue 可取消的延迟入队
func (q *DelayLkQueue[TKey, TValue]) CancellableDelayEnqueue(key TKey, value TValue, duration time.Duration) {
q.m.Lock()
defer q.m.Unlock()
if timer, ok := q.timers[key]; ok {
timer.Stop()
}
q.m.Lock()
defer q.m.Unlock()
q.timers[key] = time.AfterFunc(duration, func() {
delete(q.timers, key)
q.Enqueue(value)