In this section, we will talk about creating and using a channel of channels. Two possible reasons to use such a channel are as follows:
- For acknowledging that an operation finished its job
- For creating many worker processes that will be controlled by the same channel variable
The name of the naive program that will be developed in this section is cOfC.go and will be presented in four parts.
The first part of the program is the following:
package main import ( "fmt" ) var numbers = []int{0, -1, 2, 3, -4, 5, 6, -7, 8, 9, 10}
The second part of the program is the following:
func f1(cc chan chan int, finished chan struct{}) { c := make(chan int) cc <- c defer close(c) total := 0 i := 0 for { select { case c <- numbers[i]: i = i + 1 i = i % len(numbers)...