Writing concurrent programs
Up to this point, the discussions about goroutines and channels remained deliberately separated to ensure that each topic is properly covered. However, the true power of channels and goroutines are realized when they are combined to create concurrent programs, as covered in this section.
Synchronization
One of the primary uses of channels is synchronization between running goroutines. To illustrate this use case, let us examine the following code, which implements a word histogram. The program reads the words from the data
slice then, on a separate goroutine, collects the occurrence of each word:
func main() { data := []string{ "The yellow fish swims slowly in the water", "The brown dog barks loudly after a drink ...", "The dark bird bird of prey lands on a small ...", } histogram := make(map[string]int) done := make(chan bool) // splits and count words ...