all jobs should be done, befor processing loop exited.
This commit is contained in:
parent
79e383a639
commit
b1bfc93f91
@ -130,7 +130,7 @@ func (worker *Worker) Work() {
|
|||||||
for _, v := range worker.clients {
|
for _, v := range worker.clients {
|
||||||
go v.Work()
|
go v.Work()
|
||||||
}
|
}
|
||||||
for worker.running {
|
for worker.running || len(worker.incoming) > 0{
|
||||||
select {
|
select {
|
||||||
case job := <-worker.incoming:
|
case job := <-worker.incoming:
|
||||||
if job == nil {
|
if job == nil {
|
||||||
@ -153,6 +153,7 @@ func (worker *Worker) Work() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(worker.incoming)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the last job in queue.
|
// Get the last job in queue.
|
||||||
@ -173,11 +174,10 @@ func (worker *Worker) LastJob() (job *WorkerJob) {
|
|||||||
|
|
||||||
// Close.
|
// Close.
|
||||||
func (worker *Worker) Close() (err error) {
|
func (worker *Worker) Close() (err error) {
|
||||||
worker.running = false
|
|
||||||
for _, v := range worker.clients {
|
for _, v := range worker.clients {
|
||||||
err = v.Close()
|
err = v.Close()
|
||||||
}
|
}
|
||||||
close(worker.incoming)
|
worker.running = false
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user