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