mirror of https://github.com/panjf2000/ants.git
fixed #7
This commit is contained in:
parent
62fc58f047
commit
e99d428a5f
7
pool.go
7
pool.go
|
@ -55,6 +55,7 @@ type Pool struct {
|
|||
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
// clear expired workers periodically.
|
||||
func (p *Pool) periodicallyPurge() {
|
||||
heartbeat := time.NewTicker(p.expiryDuration)
|
||||
|
@ -77,7 +78,11 @@ func (p *Pool) periodicallyPurge() {
|
|||
}
|
||||
n++
|
||||
if n > 0 {
|
||||
p.workers = idleWorkers[n:]
|
||||
if n >= cap(idleWorkers) {
|
||||
p.workers = idleWorkers[:0]
|
||||
} else {
|
||||
p.workers = idleWorkers[n:]
|
||||
}
|
||||
}
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
|
|
@ -79,7 +79,11 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
|||
}
|
||||
n++
|
||||
if n > 0 {
|
||||
p.workers = idleWorkers[n:]
|
||||
if n >= cap(idleWorkers) {
|
||||
p.workers = idleWorkers[:0]
|
||||
} else {
|
||||
p.workers = idleWorkers[n:]
|
||||
}
|
||||
}
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue