Skip to content

Commit

Permalink
chore: rename the internal method in workerQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Apr 4, 2023
1 parent 650c9db commit 73defa0
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion worker_loop_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions worker_loop_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down Expand Up @@ -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")

Expand All @@ -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")

Expand All @@ -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")
}
2 changes: 1 addition & 1 deletion worker_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion worker_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion worker_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 73defa0

Please sign in to comment.