February 2019
Intermediate to advanced
450 pages
11h 59m
English
As we've seen in earlier chapters, goroutines offer powerful but simple concurrent operation. Most of these examples have been generating output or responding to user requests, but long running processes are often generating data that needs to be utilized by the application. In this example, we see how a channel can be used to effectively gather data from multiple threads to aggregate and report.
Our example is a simple tool that'll get the disk usage of a directory. For each element within this directory, we'll start a goroutine (dirSize()) that'll calculate the space used by the directory and the files it contains. This function returns the result through a channel so the application can use the information ...
Read now
Unlock full access