Using channels and the select statement
Go channels, in combination with goroutines, are first-class citizens for asynchronous communication. Channels become especially powerful when using select statements. These statements allow a goroutine to intelligently handle requests from multiple channels at once.
Getting ready
Configure your environment according to these steps:
- Download and install Go on your operating system from https://golang.org/doc/install and configure your
GOPATH
environment variable. - Open a terminal/console application.
- Navigate to
GOPATH/src
and create a project directory, such as$GOPATH/src/github.com/yourusername/customrepo
.
All code will be run and modified from this directory.
- Optionally, install the latest tested version of the code using the
go get github.com/agtorre/go-cookbook/
command.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter9/channels
directory and navigate to it. - Copy tests from...