diff --git a/worker.go b/worker.go index 0eecd2c..1b1f817 100644 --- a/worker.go +++ b/worker.go @@ -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 { diff --git a/worker_func.go b/worker_func.go index 0d119df..3f46d72 100644 --- a/worker_func.go +++ b/worker_func.go @@ -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 {