mirror of https://github.com/panjf2000/ants.git
Optimize the logic when putting worker back to sync.Pool
This commit is contained in:
parent
023672e877
commit
8cbfb5dd67
|
@ -49,6 +49,7 @@ func (w *goWorker) run() {
|
|||
go func() {
|
||||
defer func() {
|
||||
w.pool.decRunning()
|
||||
w.pool.workerCache.Put(w)
|
||||
if p := recover(); p != nil {
|
||||
if ph := w.pool.options.PanicHandler; ph != nil {
|
||||
ph(p)
|
||||
|
@ -59,7 +60,6 @@ func (w *goWorker) run() {
|
|||
log.Printf("worker exits from panic: %s\n", string(buf[:n]))
|
||||
}
|
||||
}
|
||||
w.pool.workerCache.Put(w)
|
||||
}()
|
||||
|
||||
for f := range w.task {
|
||||
|
|
|
@ -49,6 +49,7 @@ func (w *goWorkerWithFunc) run() {
|
|||
go func() {
|
||||
defer func() {
|
||||
w.pool.decRunning()
|
||||
w.pool.workerCache.Put(w)
|
||||
if p := recover(); p != nil {
|
||||
if ph := w.pool.options.PanicHandler; ph != nil {
|
||||
ph(p)
|
||||
|
@ -59,7 +60,6 @@ func (w *goWorkerWithFunc) run() {
|
|||
log.Printf("worker with func exits from panic: %s\n", string(buf[:n]))
|
||||
}
|
||||
}
|
||||
w.pool.workerCache.Put(w)
|
||||
}()
|
||||
|
||||
for args := range w.args {
|
||||
|
|
Loading…
Reference in New Issue