Sometimes, it is useful to perform a number of operations asynchronously, and then wait until they complete before moving on. For example, if an operation requires pulling information from multiple APIs and aggregating that information, it can be helpful to make those client requests asynchronously. This recipe will explore using sync.WaitGroup to orchestrate non-dependent tasks in parallel.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application,createa new directory called~/projects/go-programming-cookbook/chapter10/waitgroupand navigate to it.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second-Edition/chapter10/waitgroup
You should see a file calledgo.modthat contains the following content:
module github.com/PacktPublishing/Go...