Executing parallel and async client requests
Performing client requests in parallel is relatively simple in Go. In the following recipe, we'll use a client to retrieve multiple URLs using Go buffered channels. Responses and errors will both go to a separate channel that is readily accessible by anyone with access to the client.
In the case of this recipe, creation of the client, reading the channels, and handling of responses and errors will all be done in the main.go
file.
Getting ready
Refer to the Getting ready section of the Initializing, storing, and passing http.Client structs recipe in this chapter.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter6/async
directory and navigate to it. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter6/async or use this as an exercise to write some of your own code.
- Create a file called
config.go
with the following content:
package async ...