Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Distributed Computing with Go

You're reading from   Distributed Computing with Go Practical concurrency and parallelism for Go applications

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781787125384
Length 246 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
V.N. Nikhil Anurag V.N. Nikhil Anurag
Author Profile Icon V.N. Nikhil Anurag
V.N. Nikhil Anurag
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Developer Environment for Go 2. Understanding Goroutines FREE CHAPTER 3. Channels and Messages 4. The RESTful Web 5. Introducing Goophr 6. Goophr Concierge 7. Goophr Librarian 8. Deploying Goophr 9. Foundations of Web Scale Architecture 10. Other Books You May Enjoy

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 
package main 
 
import "fmt" 
 
func main() { 
    channels := [5](chan int){ 
        make(chan int), ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime