New creates a new work pool.
(maxGoroutines int)
| 19 | |
| 20 | // New creates a new work pool. |
| 21 | func New(maxGoroutines int) *Pool { |
| 22 | p := Pool{ |
| 23 | work: make(chan Worker), |
| 24 | } |
| 25 | |
| 26 | p.wg.Add(maxGoroutines) |
| 27 | for i := 0; i < maxGoroutines; i++ { |
| 28 | go func() { |
| 29 | for w := range p.work { |
| 30 | w.Task() |
| 31 | } |
| 32 | p.wg.Done() |
| 33 | }() |
| 34 | } |
| 35 | |
| 36 | return &p |
| 37 | } |
| 38 | |
| 39 | // Run submits work to the pool. |
| 40 | func (p *Pool) Run(w Worker) { |