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

Closing channels

In the previous sections, we have looked at three types of channels and how to create them. In this section, let's look at how to close the channels and how this might affect sending and receiving on these channels. We close a channel when we no longer want to send any messages on the said channel. How a channel behaves after being closed is different for each type of channel. Let's dive into them:

  • Unbuffered closed channel: Sending messages will cause panic and receiving on it will yield an immediate zero value of the channel's element type.
  • Buffered closed channel: Sending messages will cause panic but receiving on it will first yield all the values in the channel's queue. Once the queue has been exhausted, then the channel ...

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