diff --git a/pool.go b/pool.go index 36fe5cb..4c7309f 100644 --- a/pool.go +++ b/pool.go @@ -62,6 +62,8 @@ type Pool struct { // clear expired workers periodically. func (p *Pool) periodicallyPurge() { heartbeat := time.NewTicker(p.expiryDuration) + defer heartbeat.Stop() + for range heartbeat.C { currentTime := time.Now() p.lock.Lock() diff --git a/pool_func.go b/pool_func.go index fbcbe9d..5c46689 100644 --- a/pool_func.go +++ b/pool_func.go @@ -63,6 +63,8 @@ type PoolWithFunc struct { // clear expired workers periodically. func (p *PoolWithFunc) periodicallyPurge() { heartbeat := time.NewTicker(p.expiryDuration) + defer heartbeat.Stop() + for range heartbeat.C { currentTime := time.Now() p.lock.Lock()