优化延迟无锁队列中的持续监听逻辑
This commit is contained in:
parent
7ae884a559
commit
39970847c6
@ -21,13 +21,12 @@ func (q *DelayLkQueue[T]) DelayEnqueue(value T, duration time.Duration) {
|
||||
// ContinuousDequeue 持续监听出队通知
|
||||
func (q *DelayLkQueue[T]) ContinuousDequeue(notify ...chan T) {
|
||||
for {
|
||||
value, ok := q.Dequeue()
|
||||
if !ok {
|
||||
if value, ok := q.Dequeue(); ok {
|
||||
for _, n := range notify {
|
||||
n <- value
|
||||
}
|
||||
} else {
|
||||
time.Sleep(time.Millisecond) // 队列为空,休眠1毫秒
|
||||
continue
|
||||
}
|
||||
for _, n := range notify {
|
||||
n <- value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user