From d6076c09aa1c1a7d190fe70d00c1332bf72982a0 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 14 Apr 2019 11:29:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=99=84=20Improvement=20in=20`periodically?= =?UTF-8?q?Purge`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pool.go | 7 +++---- pool_func.go | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pool.go b/pool.go index dcd71b4..338d94f 100644 --- a/pool.go +++ b/pool.go @@ -69,13 +69,12 @@ func (p *Pool) periodicallyPurge() { defer heartbeat.Stop() for range heartbeat.C { + if CLOSED == atomic.LoadInt32(&p.release) { + break + } currentTime := time.Now() p.lock.Lock() idleWorkers := p.workers - if CLOSED == atomic.LoadInt32(&p.release) { - p.lock.Unlock() - return - } n := -1 for i, w := range idleWorkers { if currentTime.Sub(w.recycleTime) <= p.expiryDuration { diff --git a/pool_func.go b/pool_func.go index 623c60f..b8ef5ab 100644 --- a/pool_func.go +++ b/pool_func.go @@ -72,13 +72,12 @@ func (p *PoolWithFunc) periodicallyPurge() { defer heartbeat.Stop() for range heartbeat.C { + if CLOSED == atomic.LoadInt32(&p.release) { + break + } currentTime := time.Now() p.lock.Lock() idleWorkers := p.workers - if CLOSED == atomic.LoadInt32(&p.release) { - p.lock.Unlock() - return - } n := -1 for i, w := range idleWorkers { if currentTime.Sub(w.recycleTime) <= p.expiryDuration {