diff --git a/pool.go b/pool.go index c7e9aa7..5ac1487 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 4ccbb0f..8aab29a 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()