O'Reilly logo

Distributed Computing with Go by V.N. Nikhil Anurag

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multiplexing channels

Multiplexing describes the methodology where we use a single resource to act upon multiple signals or actions. This method is used extensively in telecommunications and computer networks. We might find ourselves in a situation where we have multiple types of tasks that we want to execute. However, they can only be executed in mutual exclusion, or they need to work on a shared resource. For this, we make use of a pattern in Go known as channels multiplexing. Before we dive into how to actually multiplex channels, let's try to implement it on our own.

Imagine that we have a set of channels and we want to act on them as soon as data is sent over a channel. Here's a naïve approach on how we want to do this:

// naiveMultiplexing.go ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required