On Sun, 1 Sep 2013 19:20:02 -0700
Kyle Lemons <
kev...@google.com> wrote:
> Remember the rules of optimization:
> 1. Don't optimize.
> 2. (experts only) Don't optimize yet.
>
> If you're reading a file from magnetic storage, there's a nonzero
> probability that reading the data from the drive is going to be
> slower than the entirety of the processing you need to do on the file.
>
> That being said, however, the idea is very natural with goroutines:
>
http://play.golang.org/p/_9daZBbJXT
[...]
I'd note that the prospective process() function missing in the example
should call wg.Done() after it completed its task -- preferably using a
deferred call placed somewhere at the beginning, like this:
func process(wg sync.WaitGroup, lines []string) {
defer wg.Done()
for _, line := range lines {
// do something with the line...
}
}