forked from mirror/ants
Merge branch 'develop'
This commit is contained in:
commit
b7c241d8ac
5
pool.go
5
pool.go
|
@ -55,6 +55,7 @@ type Pool struct {
|
||||||
|
|
||||||
once sync.Once
|
once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear expired workers periodically.
|
// clear expired workers periodically.
|
||||||
func (p *Pool) periodicallyPurge() {
|
func (p *Pool) periodicallyPurge() {
|
||||||
heartbeat := time.NewTicker(p.expiryDuration)
|
heartbeat := time.NewTicker(p.expiryDuration)
|
||||||
|
@ -77,8 +78,12 @@ func (p *Pool) periodicallyPurge() {
|
||||||
}
|
}
|
||||||
n++
|
n++
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
|
if n >= cap(idleWorkers) {
|
||||||
|
p.workers = idleWorkers[:0]
|
||||||
|
} else {
|
||||||
p.workers = idleWorkers[n:]
|
p.workers = idleWorkers[n:]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,12 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
||||||
}
|
}
|
||||||
n++
|
n++
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
|
if n >= cap(idleWorkers) {
|
||||||
|
p.workers = idleWorkers[:0]
|
||||||
|
} else {
|
||||||
p.workers = idleWorkers[n:]
|
p.workers = idleWorkers[n:]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue