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 {