This is a creation in Article, where the information may have evolved or changed.
There is no need to manage the grouting and channel. The following is a forward golangtc.com original:
Just wrote a package that felt worth sharing under:
Document: Https://github.com/sunfmin/fanout
To simplify the writing of concurrent programs (Goroutine, channel), this package directly overwrites the last sample program from the Go Concurrency patterns:pipelines blog.
Usually write with goroutine and channel procedures, always explode "fatal Error:all Goroutines is asleep-deadlock!", check up and difficult to find reasons.
Example program-run WHOIS with 60 goroutine to see if the domain name is still in:
inputs := []interface{}{}for _, word:= range domainWords { inputs = append(inputs, word)}results, err2 := fanout.ParallelRun(60, func(input interface{})(interface{}, error) { word := input.(string) if strings.TrimSpace(word) == "" { return nil, nil } py := pinyin.Convert(word) pydowncase := strings.ToLower(py) domain := pydowncase + ".com" outr, err := domainAvailable(word, domain) if outr.available { fmt.Printf("[Ohh Yeah] %s %s\n", outr.word, outr.domain) } else { fmt.Printf("\t\t\t %s %s %s\n", outr.word, outr.domain, outr.summary) } if err != nil { fmt.Println("Error: ", err) } return outr, nil}, inputs)fmt.Println("Finished ", len(results), ", Error:", err2)
A diagram to illustrate: