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

Method detectWords

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

Source from the content-addressed store, hash-verified

62}
63
64func (wp workerPool) detectWords() int {
65 var numWordsDetected int
66 for word := range wp.msgs {
67 // simulate work
68 length := time.Duration(rand.Int63n(50))
69 time.Sleep(length * time.Millisecond)
70 // this condition returns words like whale, whaling, whales
71 if strings.Contains(word, "whal") {
72 wp.mu.Lock()
73 numWordsDetected++
74 wp.mu.Unlock()
75 }
76 }
77 return numWordsDetected
78}
79
80// export cpu and mem profiles to a file that can be processed by pprof tool
81func runPprof(memprofile, cpuprofile string) {

Callers 1

runMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected