diff --git a/ants.go b/ants.go index 2da03045..246d91c6 100644 --- a/ants.go +++ b/ants.go @@ -97,8 +97,8 @@ var ( ) const ( - nowTimeUpdateInterval = 500 * time.Millisecond - releaseTimeoutInterval = 100 * time.Millisecond + nowTimeUpdateInterval = 500 * time.Millisecond + releaseTimeoutCount = 10 ) // Logger is used for logging formatted messages. diff --git a/pool.go b/pool.go index 5ef18745..8406da40 100644 --- a/pool.go +++ b/pool.go @@ -299,6 +299,7 @@ func (p *Pool) ReleaseTimeout(timeout time.Duration) error { } p.Release() + interval := timeout / releaseTimeoutCount endTime := time.Now().Add(timeout) for time.Now().Before(endTime) { if p.Running() == 0 && @@ -306,7 +307,7 @@ func (p *Pool) ReleaseTimeout(timeout time.Duration) error { atomic.LoadInt32(&p.ticktockDone) == 1 { return nil } - time.Sleep(releaseTimeoutInterval) + time.Sleep(interval) } return ErrTimeout } diff --git a/pool_func.go b/pool_func.go index ef3a6647..290ae36d 100644 --- a/pool_func.go +++ b/pool_func.go @@ -304,6 +304,7 @@ func (p *PoolWithFunc) ReleaseTimeout(timeout time.Duration) error { } p.Release() + interval := timeout / releaseTimeoutCount endTime := time.Now().Add(timeout) for time.Now().Before(endTime) { if p.Running() == 0 && @@ -311,7 +312,7 @@ func (p *PoolWithFunc) ReleaseTimeout(timeout time.Duration) error { atomic.LoadInt32(&p.ticktockDone) == 1 { return nil } - time.Sleep(releaseTimeoutInterval) + time.Sleep(interval) } return ErrTimeout }