How it works...
This recipe demonstrates two ways to launch a worker process that either reads or writes to a channel, and may potentially do both. The terminate conditions are a done channel, or by using a context package. The Using the context package recipe will cover the context in more detail. The main package is used to wire together the separate functions; thanks to this, it is possible to set up multiple pairs as long as the channels are not shared. In addition, it's possible to have multiple goroutines listening on the same channel, as we'll explore in the Using the worker pool design pattern recipe. Lastly, due to the asynchronous nature of goroutines, it can be tricky to establish cleanup and terminate conditions; for example, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access