diff --git a/ants.go b/ants.go index 2da0304..246d91c 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 5ef1874..8406da4 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 ef3a664..290ae36 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 }