forked from mirror/ants
fixed workers leak
This commit is contained in:
parent
50918eb4a9
commit
8556a67f0f
7
pool.go
7
pool.go
|
@ -67,7 +67,7 @@ func (p *Pool) periodicallyPurge() {
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n := 0
|
n := -1
|
||||||
for i, w := range idleWorkers {
|
for i, w := range idleWorkers {
|
||||||
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
|
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
|
||||||
break
|
break
|
||||||
|
@ -76,12 +76,11 @@ func (p *Pool) periodicallyPurge() {
|
||||||
w.task <- nil
|
w.task <- nil
|
||||||
idleWorkers[i] = nil
|
idleWorkers[i] = nil
|
||||||
}
|
}
|
||||||
n++
|
if n > -1 {
|
||||||
if n > 0 {
|
|
||||||
if n >= len(idleWorkers) {
|
if n >= len(idleWorkers) {
|
||||||
p.workers = idleWorkers[:0]
|
p.workers = idleWorkers[:0]
|
||||||
} else {
|
} else {
|
||||||
p.workers = idleWorkers[n:]
|
p.workers = idleWorkers[n+1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
|
|
|
@ -68,7 +68,7 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n := 0
|
n := -1
|
||||||
for i, w := range idleWorkers {
|
for i, w := range idleWorkers {
|
||||||
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
|
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
|
||||||
break
|
break
|
||||||
|
@ -77,12 +77,11 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
||||||
w.args <- nil
|
w.args <- nil
|
||||||
idleWorkers[i] = nil
|
idleWorkers[i] = nil
|
||||||
}
|
}
|
||||||
n++
|
if n > -1 {
|
||||||
if n > 0 {
|
|
||||||
if n >= len(idleWorkers) {
|
if n >= len(idleWorkers) {
|
||||||
p.workers = idleWorkers[:0]
|
p.workers = idleWorkers[:0]
|
||||||
} else {
|
} else {
|
||||||
p.workers = idleWorkers[n:]
|
p.workers = idleWorkers[n+1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue