(ch <-chan int, wg *sync.WaitGroup)
| 9 | ) |
| 10 | |
| 11 | func worker(ch <-chan int, wg *sync.WaitGroup) { |
| 12 | defer wg.Done() |
| 13 | for { |
| 14 | task, ok := <-ch |
| 15 | if !ok { |
| 16 | return |
| 17 | } |
| 18 | time.Sleep(1 * time.Millisecond) |
| 19 | fmt.Println("processing task", task) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | func pool(wg *sync.WaitGroup, workers, tasks int) { |
| 24 | ch := make(chan int) |