延时队列增加数量获取功能
This commit is contained in:
parent
28086ea8ee
commit
899c206c03
@ -115,6 +115,14 @@ func (q *Queues[TKey, TValue, TRoute]) Len(route TRoute) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DelayCount 获取延时队列数量
|
||||||
|
func (q *Queues[TKey, TValue, TRoute]) DelayCount(route TRoute) uint64 {
|
||||||
|
if queue, ok := q.queues.Load(route); ok {
|
||||||
|
return queue.(*DelayLkQueue[TKey, TValue]).DelayCount()
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// DelayEnqueue 延迟入队
|
// DelayEnqueue 延迟入队
|
||||||
func (q *Queues[TKey, TValue, TRoute]) DelayEnqueue(route TRoute, value TValue, duration time.Duration) {
|
func (q *Queues[TKey, TValue, TRoute]) DelayEnqueue(route TRoute, value TValue, duration time.Duration) {
|
||||||
// 入队时检查上一次出队是否确认成功
|
// 入队时检查上一次出队是否确认成功
|
||||||
|
@ -16,22 +16,14 @@ func TestQueues(t *testing.T) {
|
|||||||
route := "test"
|
route := "test"
|
||||||
q := NewQueues[struct{}, int, string]()
|
q := NewQueues[struct{}, int, string]()
|
||||||
|
|
||||||
for _, c := range cases {
|
|
||||||
q.Enqueue(route, c.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
if q.Len(route) != len(cases) {
|
|
||||||
t.Errorf("queue length error, want %d, got %d", len(cases), q.Len(route))
|
|
||||||
}
|
|
||||||
|
|
||||||
for range cases {
|
|
||||||
q.Dequeue(route)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
q.DelayEnqueue(route, c.value, c.duration)
|
q.DelayEnqueue(route, c.value, c.duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if q.DelayCount(route) != uint64(len(cases)) {
|
||||||
|
t.Errorf("queue length error, want %d, got %d", len(cases), q.DelayCount(route))
|
||||||
|
}
|
||||||
|
|
||||||
notify := make(chan int)
|
notify := make(chan int)
|
||||||
go func() {
|
go func() {
|
||||||
for data := range notify {
|
for data := range notify {
|
||||||
|
Loading…
Reference in New Issue
Block a user