One of the strengths of Go is it’s native support for concurrency. There are a lot of posts about concurrency in Go, but I was writing this up as a simple example for a coworker and decided to publish it.
It takes a little getting used to if you don’t use concurrent programming a lot, but once you get beyond a couple hurdles, it’s a rockin’ good time. In addition, you can eliminate a whole class of bugs when you force all communication through channels. Then again, you open up another kind of bug. Be careful though, it’s easy to get carried away with channels and then you can end up with some very difficult to read new age spaghetti code.
I think the term scatter/gather is an old one, but it corresponds to the fan-out/fan-in pattern in Go. I think it’s elegant and works very well.
You can play with this code on the Go Playground. For more about Go concurrency patterns check out pipelines or stay tuned! I am going to write up a few more because I have been asked by a few people about simple examples.