@cryptotaxi247 / kubo / commits / ed019e2f7

one worker

Brian Tiger Chow committed Jan 20, 2015 at 16:51 UTC ed019e2f7d0f138b7c916e28fe56da80b71a46c0
1 file changed +21 -23
blockservice/worker/worker.go
+21 -23
@@ -114,32 +114,30 @@ func (w *Worker) start(c Config) {
114 }
115 })
116
117 - for i := 0; i < c.NumWorkers; i++ {
118 - // reads from |workerChan| until process closes
119 - w.process.Go(func(proc process.Process) {
120 - ctx, cancel := context.WithCancel(context.Background())
121 -
122 - // shuts down an in-progress HasBlock operation
123 - proc.Go(func(proc process.Process) {
124 - <-proc.Closing()
125 - cancel()
126 - })
127 -
128 - for {
129 - select {
130 - case <-proc.Closing():
117 + // reads from |workerChan| until process closes
118 + w.process.Go(func(proc process.Process) {
119 + ctx, cancel := context.WithCancel(context.Background())
120 +
121 + // shuts down an in-progress HasBlock operation
122 + proc.Go(func(proc process.Process) {
123 + <-proc.Closing()
124 + cancel()
125 + })
126 +
127 + for {
128 + select {
129 + case <-proc.Closing():
130 + return
131 + case block, ok := <-workerChan:
132 + if !ok {
133 return
132 - case block, ok := <-workerChan:
133 - if !ok {
134 - return
135 - }
136 - if err := w.exchange.HasBlock(ctx, block); err != nil {
137 - // TODO log event?
138 - }
134 + }
135 + if err := w.exchange.HasBlock(ctx, block); err != nil {
136 + // TODO log event?
137 }
138 }
141 - })
142 - }
139 + }
140 + })
141 }
142
143 type BlockList struct {