opt: calculate the interval for ReleaseTimeout() based on a default count (#327)

This PR reverts #325 to some extent.
This commit is contained in:
Andy Pan 2024-06-17 20:13:15 +08:00 committed by GitHub
parent b2374d5ae4
commit 3ffd3daa37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 4 deletions

View File

@ -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.

View File

@ -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
}

View File

@ -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
}