Go Concurrency Visually Explained — Channel
<p>When it comes to concurrency, many programming languages adopt the Shared Memory/State Model. However, Go distinguishes itself by implementing <em>Communicating Sequential Processes (CSP)</em>. In CSP, a program consists of parallel processes that do not share state; instead, they communicate and synchronize their actions using channels. Therefore, for developers interested in adopting Go, it becomes crucial to comprehend the workings of channels. In this article, I will illustrate channels using the delightful analogy of Gophers running their imaginary cafe, as I firmly believe that humans are better visual learners.</p>
<h2>Scenario</h2>
<p>Partier, Candier, and Stringer are running a cafe. Given that making coffee takes more time than accepting orders, Partier will assist with accepting orders from customers and then pass those orders to the kitchen, where Candier and Stringer prepare the coffee.</p>
<p><img alt="" src="https://miro.medium.com/v2/resize:fit:700/1*FeBWPRLv6XvgolYnE1C3fA.png" style="height:557px; width:700px" /></p>
<p>Gopher’s Cafe</p>
<h2>Unbuffered Channels</h2>
<p>Initially, the cafe operates in the simplest manner: Whenever a new order is received, Partier puts the order in the Channel and waits until either Candier or Stringer takes it before accepting any new orders. This communication between Partier and the kitchen is achieved using an unbuffered channel, created with <code>ch := make(chan Order)</code>. When there are no pending orders in the channel, even if both Stringer and Candier are ready to take new orders, they remain idle and wait for a new order to arrive.</p>
<p><a href="https://blog.stackademic.com/go-concurrency-visually-explained-channel-c6f88070aafa">Click Here</a></p>