These steps cover writing and running your application:
- From your terminal/console application, create the chapter9/pool directory and navigate to it.
- Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter9/pool or use this as an exercise to write some of your own code.
- Create a file called worker.go with the following content:
package pool import ( "context" "fmt" ) // Dispatch creates numWorker workers, returns a cancel // function channels for adding work and responses, // cancel must be called func Dispatch(numWorker int) (context.CancelFunc, chan WorkRequest, chan WorkResponse) { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) in := make(chan WorkRequest, 10) out := make(chan ...