type Work struct { | |
x, y, z int | |
} | |
func worker(in <-chan *Work, out chan<- *Work) { | |
for w := range in { | |
w.z = w.x * w.y | |
Sleep(w.z) | |
out <- w | |
} | |
} | |
func Run() { | |
in, out := make(chan *Work), make(chan *Work) | |
for i := 0; i < NumWorkers; i++ { | |
go worker(in, out) | |
} | |
go sendLotsOfWork(in) | |
receiveLotsOfResults(out) | |
} |