A pool is a fixed set of goroutines reading from one jobs channel and writing to one results channel. Closing the jobs channel tells every worker to exit after it has drained the work. |
|
The main flow sends five jobs, closes the jobs channel, and collects five results. Sorting them makes the printout independent of which worker finished first. |
|
Each job is doubled. |
|
Next example: Wait Groups.