mirror of https://github.com/panjf2000/ants.git
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
4
ants.go
4
ants.go
|
@ -97,8 +97,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
nowTimeUpdateInterval = 500 * time.Millisecond
|
nowTimeUpdateInterval = 500 * time.Millisecond
|
||||||
releaseTimeoutInterval = 100 * time.Millisecond
|
releaseTimeoutCount = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
// Logger is used for logging formatted messages.
|
// 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()
|
p.Release()
|
||||||
|
|
||||||
|
interval := timeout / releaseTimeoutCount
|
||||||
endTime := time.Now().Add(timeout)
|
endTime := time.Now().Add(timeout)
|
||||||
for time.Now().Before(endTime) {
|
for time.Now().Before(endTime) {
|
||||||
if p.Running() == 0 &&
|
if p.Running() == 0 &&
|
||||||
|
@ -306,7 +307,7 @@ func (p *Pool) ReleaseTimeout(timeout time.Duration) error {
|
||||||
atomic.LoadInt32(&p.ticktockDone) == 1 {
|
atomic.LoadInt32(&p.ticktockDone) == 1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
time.Sleep(releaseTimeoutInterval)
|
time.Sleep(interval)
|
||||||
}
|
}
|
||||||
return ErrTimeout
|
return ErrTimeout
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,6 +304,7 @@ func (p *PoolWithFunc) ReleaseTimeout(timeout time.Duration) error {
|
||||||
}
|
}
|
||||||
p.Release()
|
p.Release()
|
||||||
|
|
||||||
|
interval := timeout / releaseTimeoutCount
|
||||||
endTime := time.Now().Add(timeout)
|
endTime := time.Now().Add(timeout)
|
||||||
for time.Now().Before(endTime) {
|
for time.Now().Before(endTime) {
|
||||||
if p.Running() == 0 &&
|
if p.Running() == 0 &&
|
||||||
|
@ -311,7 +312,7 @@ func (p *PoolWithFunc) ReleaseTimeout(timeout time.Duration) error {
|
||||||
atomic.LoadInt32(&p.ticktockDone) == 1 {
|
atomic.LoadInt32(&p.ticktockDone) == 1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
time.Sleep(releaseTimeoutInterval)
|
time.Sleep(interval)
|
||||||
}
|
}
|
||||||
return ErrTimeout
|
return ErrTimeout
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue