Merge branch 'develop'

This commit is contained in:
andy pan 2018-08-08 18:08:22 +08:00
commit b7c241d8ac
2 changed files with 11 additions and 2 deletions

View File

@ -55,6 +55,7 @@ type Pool struct {
once sync.Once once sync.Once
} }
// clear expired workers periodically. // clear expired workers periodically.
func (p *Pool) periodicallyPurge() { func (p *Pool) periodicallyPurge() {
heartbeat := time.NewTicker(p.expiryDuration) heartbeat := time.NewTicker(p.expiryDuration)
@ -77,7 +78,11 @@ func (p *Pool) periodicallyPurge() {
} }
n++ n++
if n > 0 { if n > 0 {
p.workers = idleWorkers[n:] if n >= cap(idleWorkers) {
p.workers = idleWorkers[:0]
} else {
p.workers = idleWorkers[n:]
}
} }
p.lock.Unlock() p.lock.Unlock()
} }

View File

@ -79,7 +79,11 @@ func (p *PoolWithFunc) periodicallyPurge() {
} }
n++ n++
if n > 0 { if n > 0 {
p.workers = idleWorkers[n:] if n >= cap(idleWorkers) {
p.workers = idleWorkers[:0]
} else {
p.workers = idleWorkers[n:]
}
} }
p.lock.Unlock() p.lock.Unlock()
} }