mirror of
https://github.com/panjf2000/ants.git
synced 2025-12-16 09:51:02 +00:00
opt: calculate the interval for ReleaseTimeout() based on a default count (#327)
This PR reverts #325 to some extent.
This commit is contained in:
parent
b2374d5ae4
commit
3ffd3daa37
2
ants.go
2
ants.go
@ -98,7 +98,7 @@ var (
|
||||
|
||||
const (
|
||||
nowTimeUpdateInterval = 500 * time.Millisecond
|
||||
releaseTimeoutInterval = 100 * time.Millisecond
|
||||
releaseTimeoutCount = 10
|
||||
)
|
||||
|
||||
// Logger is used for logging formatted messages.
|
||||
|
||||
3
pool.go
3
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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user