From b1bfc93f91ece16c5ff3d3e79b2405b981a575bd Mon Sep 17 00:00:00 2001 From: mikespook Date: Wed, 28 Mar 2012 11:27:57 +0800 Subject: [PATCH] all jobs should be done, befor processing loop exited. --- gearman/worker/worker.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gearman/worker/worker.go b/gearman/worker/worker.go index 9e23c2c..4c95e4e 100644 --- a/gearman/worker/worker.go +++ b/gearman/worker/worker.go @@ -130,7 +130,7 @@ func (worker *Worker) Work() { for _, v := range worker.clients { go v.Work() } - for worker.running { + for worker.running || len(worker.incoming) > 0{ select { case job := <-worker.incoming: if job == nil { @@ -153,6 +153,7 @@ func (worker *Worker) Work() { } } } + close(worker.incoming) } // Get the last job in queue. @@ -173,11 +174,10 @@ func (worker *Worker) LastJob() (job *WorkerJob) { // Close. func (worker *Worker) Close() (err error) { - worker.running = false for _, v := range worker.clients { err = v.Close() } - close(worker.incoming) + worker.running = false return err }