Using the worker pool design pattern
The worker pool design pattern is one where you dispatch long-running goroutines as workers. These workers can process a variety of work either using multiple channels or by using a stateful request struct that specifies the type as described in the preceding recipe.
This recipe will create stateful workers and demonstrate how to coordinate and spin up multiple workers all handling requests concurrently on the same channel. These workers will be crypto workers like in a web authentication app. Their purpose will be to hash plain text strings using bcrypt
package and compare a text password against a hash.
Getting ready
Refer to the Getting ready section of the Using channels and the select statement recipe in this chapter.
How to do it...
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...