diff --git a/pool.go b/pool.go index 656bf19..7a7a48e 100644 --- a/pool.go +++ b/pool.go @@ -67,7 +67,7 @@ func (p *Pool) periodicallyPurge() { p.lock.Unlock() return } - n := 0 + n := -1 for i, w := range idleWorkers { if currentTime.Sub(w.recycleTime) <= p.expiryDuration { break @@ -76,12 +76,11 @@ func (p *Pool) periodicallyPurge() { w.task <- nil idleWorkers[i] = nil } - n++ - if n > 0 { + if n > -1 { if n >= len(idleWorkers) { p.workers = idleWorkers[:0] } else { - p.workers = idleWorkers[n:] + p.workers = idleWorkers[n+1:] } } p.lock.Unlock() diff --git a/pool_func.go b/pool_func.go index 0b2eed5..7c0df59 100644 --- a/pool_func.go +++ b/pool_func.go @@ -68,7 +68,7 @@ func (p *PoolWithFunc) periodicallyPurge() { p.lock.Unlock() return } - n := 0 + n := -1 for i, w := range idleWorkers { if currentTime.Sub(w.recycleTime) <= p.expiryDuration { break @@ -77,12 +77,11 @@ func (p *PoolWithFunc) periodicallyPurge() { w.args <- nil idleWorkers[i] = nil } - n++ - if n > 0 { + if n > -1 { if n >= len(idleWorkers) { p.workers = idleWorkers[:0] } else { - p.workers = idleWorkers[n:] + p.workers = idleWorkers[n+1:] } } p.lock.Unlock()