优化延时队列及队列集合的逻辑
This commit is contained in:
parent
800c590a3a
commit
f36180bc8a
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user