package main import ( "fmt" "sync" ) func worker(id int, jobs <-chan int, results chan<- int, wg *sync.WaitGroup) { defer wg.Done() for n := range jobs { results <- n * n } }
Write a worker pool in Go: 4 goroutines take numbers from a jobs channel, square each one and send it to a results channel. The main function submits 20 jobs, waits for the workers with sync.WaitGroup and collects the results. Explain the order in which the channels are closed.
