MCPcopy Index your code
hub / github.com/goinaction/code / New

Function New

chapter7/patterns/work/work.go:21–37  ·  view source on GitHub ↗

New creates a new work pool.

(maxGoroutines int)

Source from the content-addressed store, hash-verified

19
20// New creates a new work pool.
21func 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.
40func (p *Pool) Run(w Worker) {

Callers

nothing calls this directly

Calls 2

AddMethod · 0.80
TaskMethod · 0.65

Tested by

no test coverage detected