File tree Expand file tree Collapse file tree 1 file changed +5
-13
lines changed
Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Original file line number Diff line number Diff line change @@ -194,7 +194,7 @@ Loop:
194194 // Create a new worker, if not at max.
195195 if workerCount < p .maxWorkers {
196196 wg .Add (1 )
197- go startWorker (task , p .workerQueue , & wg )
197+ go worker (task , p .workerQueue , & wg )
198198 workerCount ++
199199 } else {
200200 // Enqueue task to be executed by next available worker.
@@ -231,21 +231,13 @@ Loop:
231231 timeout .Stop ()
232232}
233233
234- // startWorker runs initial task, then starts a worker waiting for more.
235- func startWorker (task func (), workerQueue chan func (), wg * sync.WaitGroup ) {
236- task ()
237- go worker (workerQueue , wg )
238- }
239-
240234// worker executes tasks and stops when it receives a nil task.
241- func worker (workerQueue chan func (), wg * sync.WaitGroup ) {
242- for task := range workerQueue {
243- if task == nil {
244- wg .Done ()
245- return
246- }
235+ func worker (task func (), workerQueue chan func (), wg * sync.WaitGroup ) {
236+ for task != nil {
247237 task ()
238+ task = <- workerQueue
248239 }
240+ wg .Done ()
249241}
250242
251243// stop tells the dispatcher to exit, and whether or not to complete queued
You can’t perform that action at this time.
0 commit comments