diff --git a/lock_free/delay_queue.go b/lock_free/delay_queue.go index 50328c9..417340e 100644 --- a/lock_free/delay_queue.go +++ b/lock_free/delay_queue.go @@ -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)