From b21f63142d492e0bcb0250a2be907b53a80e89d7 Mon Sep 17 00:00:00 2001 From: andy pan Date: Fri, 6 Jul 2018 14:56:59 +0800 Subject: [PATCH] fixed the "slice bounds out of range" error --- pool.go | 6 ++++-- pool_func.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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() } }()