mirror of https://github.com/panjf2000/ants.git
chore: rename the internal method in workerQueue
This commit is contained in:
parent
650c9db322
commit
73defa0289
2
pool.go
2
pool.go
|
@ -91,7 +91,7 @@ func (p *Pool) purgeStaleWorkers(ctx context.Context) {
|
|||
}
|
||||
|
||||
p.lock.Lock()
|
||||
staleWorkers := p.workers.staleWorkers(p.options.ExpiryDuration)
|
||||
staleWorkers := p.workers.refresh(p.options.ExpiryDuration)
|
||||
p.lock.Unlock()
|
||||
|
||||
// Notify obsolete workers to stop.
|
||||
|
|
|
@ -92,7 +92,7 @@ func (p *PoolWithFunc) purgeStaleWorkers(ctx context.Context) {
|
|||
}
|
||||
|
||||
p.lock.Lock()
|
||||
staleWorkers := p.workers.staleWorkers(p.options.ExpiryDuration)
|
||||
staleWorkers := p.workers.refresh(p.options.ExpiryDuration)
|
||||
p.lock.Unlock()
|
||||
|
||||
// Notify obsolete workers to stop.
|
||||
|
|
|
@ -78,7 +78,7 @@ func (wq *loopQueue) detach() worker {
|
|||
return w
|
||||
}
|
||||
|
||||
func (wq *loopQueue) staleWorkers(duration time.Duration) []worker {
|
||||
func (wq *loopQueue) refresh(duration time.Duration) []worker {
|
||||
expiryTime := time.Now().Add(-duration)
|
||||
index := wq.binarySearch(expiryTime)
|
||||
if index == -1 {
|
||||
|
|
|
@ -45,7 +45,7 @@ func TestLoopQueue(t *testing.T) {
|
|||
err := q.insert(&goWorker{lastUsed: time.Now()})
|
||||
assert.Error(t, err, "Enqueue, error")
|
||||
|
||||
q.staleWorkers(time.Second)
|
||||
q.refresh(time.Second)
|
||||
assert.EqualValuesf(t, 6, q.len(), "Len error: %d", q.len())
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ func TestRetrieveExpiry(t *testing.T) {
|
|||
for i := 0; i < size/2; i++ {
|
||||
_ = q.insert(&goWorker{lastUsed: time.Now()})
|
||||
}
|
||||
workers := q.staleWorkers(u)
|
||||
workers := q.refresh(u)
|
||||
|
||||
assert.EqualValues(t, expirew, workers, "expired workers aren't right")
|
||||
|
||||
|
@ -151,7 +151,7 @@ func TestRetrieveExpiry(t *testing.T) {
|
|||
expirew = expirew[:0]
|
||||
expirew = append(expirew, q.items[size/2:]...)
|
||||
|
||||
workers2 := q.staleWorkers(u)
|
||||
workers2 := q.refresh(u)
|
||||
|
||||
assert.EqualValues(t, expirew, workers2, "expired workers aren't right")
|
||||
|
||||
|
@ -171,7 +171,7 @@ func TestRetrieveExpiry(t *testing.T) {
|
|||
expirew = append(expirew, q.items[0:3]...)
|
||||
expirew = append(expirew, q.items[size/2:]...)
|
||||
|
||||
workers3 := q.staleWorkers(u)
|
||||
workers3 := q.refresh(u)
|
||||
|
||||
assert.EqualValues(t, expirew, workers3, "expired workers aren't right")
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ type workerQueue interface {
|
|||
isEmpty() bool
|
||||
insert(worker) error
|
||||
detach() worker
|
||||
staleWorkers(duration time.Duration) []worker
|
||||
refresh(duration time.Duration) []worker // clean up the stale workers and return them
|
||||
reset()
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ func (wq *workerStack) detach() worker {
|
|||
return w
|
||||
}
|
||||
|
||||
func (wq *workerStack) staleWorkers(duration time.Duration) []worker {
|
||||
func (wq *workerStack) refresh(duration time.Duration) []worker {
|
||||
n := wq.len()
|
||||
if n == 0 {
|
||||
return nil
|
||||
|
|
|
@ -45,7 +45,7 @@ func TestWorkerStack(t *testing.T) {
|
|||
}
|
||||
}
|
||||
assert.EqualValues(t, 12, q.len(), "Len error")
|
||||
q.staleWorkers(time.Second)
|
||||
q.refresh(time.Second)
|
||||
assert.EqualValues(t, 6, q.len(), "Len error")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue