From ed019e2f7d0f138b7c916e28fe56da80b71a46c0 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 20 Jan 2015 16:51:45 -0800 Subject: [PATCH] one worker --- blockservice/worker/worker.go | 40 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/blockservice/worker/worker.go b/blockservice/worker/worker.go index 0da792719..a3d55a155 100644 --- a/blockservice/worker/worker.go +++ b/blockservice/worker/worker.go @@ -114,32 +114,30 @@ func (w *Worker) start(c Config) { } }) - for i := 0; i < c.NumWorkers; i++ { - // reads from |workerChan| until process closes - w.process.Go(func(proc process.Process) { - ctx, cancel := context.WithCancel(context.Background()) + // reads from |workerChan| until process closes + w.process.Go(func(proc process.Process) { + ctx, cancel := context.WithCancel(context.Background()) - // shuts down an in-progress HasBlock operation - proc.Go(func(proc process.Process) { - <-proc.Closing() - cancel() - }) + // shuts down an in-progress HasBlock operation + proc.Go(func(proc process.Process) { + <-proc.Closing() + cancel() + }) - for { - select { - case <-proc.Closing(): + for { + select { + case <-proc.Closing(): + return + case block, ok := <-workerChan: + if !ok { return - case block, ok := <-workerChan: - if !ok { - return - } - if err := w.exchange.HasBlock(ctx, block); err != nil { - // TODO log event? - } + } + if err := w.exchange.HasBlock(ctx, block); err != nil { + // TODO log event? } } - }) - } + } + }) } type BlockList struct {