diff --git a/pool.go b/pool.go index 40f2ba1..755e32d 100644 --- a/pool.go +++ b/pool.go @@ -77,8 +77,10 @@ func (p *Pool) monitorAndClear() { w.stop() idleWorkers[i] = nil } - n += 1 - p.workers = idleWorkers[n:] + if n > 0 { + n += 1 + p.workers = idleWorkers[n:] + } p.lock.Unlock() } }() diff --git a/pool_func.go b/pool_func.go index 3d92730..f583600 100644 --- a/pool_func.go +++ b/pool_func.go @@ -78,8 +78,10 @@ func (p *PoolWithFunc) MonitorAndClear() { w.stop() idleWorkers[i] = nil } - n += 1 - p.workers = idleWorkers[n:] + if n > 0 { + n += 1 + p.workers = idleWorkers[n:] + } p.lock.Unlock() } }()