8 Selecting channels

This chapter covers

  • Selecting from multiple channels
  • Disabling select cases
  • Choosing between message passing and memory sharing

In the previous chapter, we used channels to implement message passing between two goroutines. In this chapter, we will see how to use Go’s select statement to read and write messages on multiple channels and to implement timeouts and non-blocking channels. We will also examine a technique for excluding channels that have been closed and consuming only from the remaining open channels. Finally, we’ll discuss memory sharing versus message passing and when we should choose one technique over the other.

8.1 Combining multiple channels

How can we have one goroutine respond to messages coming from different ...

Get Learn Concurrent Programming with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.