From 0d650f5c1e6ecde449db0f401064e36ad06d012c Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 17 Jun 2024 18:21:01 +0800 Subject: [PATCH] opt: increase the interval of waiting in ReleaseTimeout() (#325) --- ants.go | 5 ++++- pool.go | 2 +- pool_func.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ants.go b/ants.go index 4b61ba2b..2da03045 100644 --- a/ants.go +++ b/ants.go @@ -96,7 +96,10 @@ var ( defaultAntsPool, _ = NewPool(DefaultAntsPoolSize) ) -const nowTimeUpdateInterval = 500 * time.Millisecond +const ( + nowTimeUpdateInterval = 500 * time.Millisecond + releaseTimeoutInterval = 100 * time.Millisecond +) // Logger is used for logging formatted messages. type Logger interface { diff --git a/pool.go b/pool.go index c69dde57..5ef18745 100644 --- a/pool.go +++ b/pool.go @@ -306,7 +306,7 @@ func (p *Pool) ReleaseTimeout(timeout time.Duration) error { atomic.LoadInt32(&p.ticktockDone) == 1 { return nil } - time.Sleep(10 * time.Millisecond) + time.Sleep(releaseTimeoutInterval) } return ErrTimeout } diff --git a/pool_func.go b/pool_func.go index 6840384a..ef3a6647 100644 --- a/pool_func.go +++ b/pool_func.go @@ -311,7 +311,7 @@ func (p *PoolWithFunc) ReleaseTimeout(timeout time.Duration) error { atomic.LoadInt32(&p.ticktockDone) == 1 { return nil } - time.Sleep(10 * time.Millisecond) + time.Sleep(releaseTimeoutInterval) } return ErrTimeout }