mirror of https://github.com/panjf2000/ants.git
worker: decRunning when revertWorker is false
Signed-off-by: Cholerae Hu <choleraehyq@gmail.com>
This commit is contained in:
parent
280ac345a8
commit
d6cd5a7e72
|
@ -48,9 +48,8 @@ func (w *goWorker) run() {
|
||||||
w.pool.incRunning()
|
w.pool.incRunning()
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
w.pool.decRunning()
|
||||||
if p := recover(); p != nil {
|
if p := recover(); p != nil {
|
||||||
w.pool.decRunning()
|
|
||||||
w.pool.workerCache.Put(w)
|
|
||||||
if w.pool.panicHandler != nil {
|
if w.pool.panicHandler != nil {
|
||||||
w.pool.panicHandler(p)
|
w.pool.panicHandler(p)
|
||||||
} else {
|
} else {
|
||||||
|
@ -60,17 +59,16 @@ func (w *goWorker) run() {
|
||||||
log.Printf("worker exits from panic: %s\n", string(buf[:n]))
|
log.Printf("worker exits from panic: %s\n", string(buf[:n]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
w.pool.workerCache.Put(w)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for f := range w.task {
|
for f := range w.task {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
w.pool.decRunning()
|
|
||||||
w.pool.workerCache.Put(w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f()
|
f()
|
||||||
if ok := w.pool.revertWorker(w); !ok {
|
if ok := w.pool.revertWorker(w); !ok {
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -48,9 +48,8 @@ func (w *goWorkerWithFunc) run() {
|
||||||
w.pool.incRunning()
|
w.pool.incRunning()
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
w.pool.decRunning()
|
||||||
if p := recover(); p != nil {
|
if p := recover(); p != nil {
|
||||||
w.pool.decRunning()
|
|
||||||
w.pool.workerCache.Put(w)
|
|
||||||
if w.pool.panicHandler != nil {
|
if w.pool.panicHandler != nil {
|
||||||
w.pool.panicHandler(p)
|
w.pool.panicHandler(p)
|
||||||
} else {
|
} else {
|
||||||
|
@ -60,17 +59,16 @@ func (w *goWorkerWithFunc) run() {
|
||||||
log.Printf("worker with func exits from panic: %s\n", string(buf[:n]))
|
log.Printf("worker with func exits from panic: %s\n", string(buf[:n]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
w.pool.workerCache.Put(w)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for args := range w.args {
|
for args := range w.args {
|
||||||
if args == nil {
|
if args == nil {
|
||||||
w.pool.decRunning()
|
|
||||||
w.pool.workerCache.Put(w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.pool.poolFunc(args)
|
w.pool.poolFunc(args)
|
||||||
if ok := w.pool.revertWorker(w); !ok {
|
if ok := w.pool.revertWorker(w); !ok {
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue