🙄 Improvement in `periodicallyPurge`

This commit is contained in:
Andy Pan 2019-04-14 11:29:25 +08:00
parent 00294fd50b
commit d6076c09aa
2 changed files with 6 additions and 8 deletions

View File

@ -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 {

View File

@ -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 {