From 09852e05d70fb99b6903a5230a4fca90cb4d71e1 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Tue, 25 Dec 2018 14:47:00 -0600 Subject: [PATCH] Simplify close logic --- pool.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/pool.go b/pool.go index 2d21c0d..28d2f50 100644 --- a/pool.go +++ b/pool.go @@ -250,12 +250,6 @@ func (p *Pool) lockedAvailableGet() interface{} { return rw.resource } -func (p *Pool) backgroundClose(res interface{}) { - go func() { - p.closeRes(res) - }() -} - // Return returns res to the the pool. If res is not part of the pool Return // will panic. func (p *Pool) Return(res interface{}) { @@ -267,17 +261,11 @@ func (p *Pool) Return(res interface{}) { panic("Return called on resource that does not belong to pool") } - if p.closed { - delete(p.allResources, rw.resource) - p.cond.L.Unlock() - p.backgroundClose(rw.resource) - return - } - closeResource := true now := time.Now() - if now.Sub(rw.creationTime) > p.maxResourceDuration { + if p.closed { + } else if now.Sub(rw.creationTime) > p.maxResourceDuration { } else if p.maxResourceCheckouts <= rw.checkoutCount { // use <= instead of == as maxResourceCheckouts may be lowered while pool is in use } else { closeResource = false @@ -286,7 +274,7 @@ func (p *Pool) Return(res interface{}) { if closeResource { delete(p.allResources, rw.resource) p.cond.L.Unlock() - p.backgroundClose(rw.resource) + go p.closeRes(rw.resource) return }