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

Method detectWords

exercise-2/main.go:50–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48}
49
50func (wp workerPool) detectWords() int {
51 var numWordsDetected int
52 for word := range wp.msgs {
53 // simulate work
54 length := time.Duration(rand.Int63n(50))
55 time.Sleep(length * time.Millisecond)
56 // this condition returns words like whale, whaling, whales
57 if strings.Contains(word, "whal") {
58 wp.mu.Lock()
59 numWordsDetected++
60 wp.mu.Unlock()
61 }
62 }
63 return numWordsDetected
64}
65
66// export cpu and mem profiles to a file that can be processed by pprof tool
67func runPprof(memprofile, cpuprofile string) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected