I would like to make the statistics routine conditional so that it only runs on certain cases otherwise it will waste cycles half the time. Right now I have one go routine act as a producer to feed the two consumer routines via buffered channels. Is there a way I can make it so the statistics routine is conditional or is there a better pattern I should follow? Thanks in advance for any and all help!
func main() {
options()
go produce(readCSV(loc))
go process()
go statistics() // only on flag
<-done
}
func produce(entries [][]string) {
regex, err := regexp.Compile(reg)
if err != nil {
log.Error(reg + ", is not a valid regular expression")
} else {
for _, each := range entries {
if regex.MatchString(each[col]) {
matches <- each
stats <- each // only on flag
}
}
}
done <- true
}
func process() {
for {
match := <-matches
if len(match) != 0 {
// PROCESS
}
}
}
func statistics() {
for {
stat := <-stats
if len(stat) != 0 {
// STATISTICS
}
}
}