From e25a58c9f36091dd67427947cf9aef059623dd54 Mon Sep 17 00:00:00 2001 From: andy pan Date: Wed, 29 Aug 2018 10:02:41 +0800 Subject: [PATCH] optimization for cleaning workers --- pool.go | 2 +- pool_func.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pool.go b/pool.go index 7a7a48e..987ba4d 100644 --- a/pool.go +++ b/pool.go @@ -77,7 +77,7 @@ func (p *Pool) periodicallyPurge() { idleWorkers[i] = nil } if n > -1 { - if n >= len(idleWorkers) { + if n >= len(idleWorkers)-1 { p.workers = idleWorkers[:0] } else { p.workers = idleWorkers[n+1:] diff --git a/pool_func.go b/pool_func.go index 7c0df59..6051117 100644 --- a/pool_func.go +++ b/pool_func.go @@ -78,7 +78,7 @@ func (p *PoolWithFunc) periodicallyPurge() { idleWorkers[i] = nil } if n > -1 { - if n >= len(idleWorkers) { + if n >= len(idleWorkers)-1 { p.workers = idleWorkers[:0] } else { p.workers = idleWorkers[n+1:]