Skip to content

Commit

Permalink
🙄 Improvement in periodicallyPurge
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Apr 14, 2019
1 parent 00294fd commit d6076c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ func (p *Pool) periodicallyPurge() {
defer heartbeat.Stop()

for range heartbeat.C {
if CLOSED == atomic.LoadInt32(&p.release) {
break
}
currentTime := time.Now()
p.lock.Lock()
idleWorkers := p.workers
if CLOSED == atomic.LoadInt32(&p.release) {
p.lock.Unlock()
return
}
n := -1
for i, w := range idleWorkers {
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
Expand Down
7 changes: 3 additions & 4 deletions pool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ func (p *PoolWithFunc) periodicallyPurge() {
defer heartbeat.Stop()

for range heartbeat.C {
if CLOSED == atomic.LoadInt32(&p.release) {
break
}
currentTime := time.Now()
p.lock.Lock()
idleWorkers := p.workers
if CLOSED == atomic.LoadInt32(&p.release) {
p.lock.Unlock()
return
}
n := -1
for i, w := range idleWorkers {
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
Expand Down

0 comments on commit d6076c0

Please sign in to comment.