MCPcopy Create free account
hub / github.com/Soypete/Production-Go-Examples / run

Method run

exercise-3/solution/main.go:25–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23}
24
25func (wp *workerPool) run() int {
26 numWords := 0
27 // start the workers in the background and wait for data on the channel
28 // we already know the number of workers, we can increase the WaitGroup once
29 wp.wg.Add(wp.numWorkers)
30 for i := 0; i < wp.numWorkers; i++ {
31 go func() {
32 defer wp.wg.Done()
33 wordsDetected := wp.detectWords()
34 wp.mu.Lock()
35 defer wp.mu.Unlock()
36 numWords = numWords + wordsDetected
37 }()
38 }
39
40 // wait for the workers to stop processing and exit
41 wp.wg.Wait()
42 return numWords
43}
44
45// getMessages gets a slice of messages to process
46func getMessages() []string {

Callers 2

benchmarkWorkersFunction · 0.95
mainFunction · 0.95

Calls 1

detectWordsMethod · 0.95

Tested by 1

benchmarkWorkersFunction · 0.76