<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>channel on Golang</title><link>https://golang.k5kc.com/tags/channel/</link><description>Recent content in channel on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:15:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/tags/channel/index.xml" rel="self" type="application/rss+xml"/><item><title>Need not close every channel</title><link>https://golang.k5kc.com/2020/08/16/need-not-close-every-channel/</link><pubDate>Sun, 16 Aug 2020 00:15:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/need-not-close-every-channel/</guid><description>You don&amp;rsquo;t need to close channel after using it, and it can be recycled automatically by the garbage collector. The following quote is from The Go Programming Language:
You needn&amp;rsquo;t close every channel when you&amp;rsquo;ve finished with it. It&amp;rsquo;s only necessary to close a channel when it is important to tell the receiving goroutines that all data have been sent. A channel that the garbage collector determines to be unreachable will have its resources reclaimed whether or not it is closed.</description></item><item><title>nil channel VS closed channel</title><link>https://golang.k5kc.com/2020/08/16/nil-channel-vs-closed-channel/</link><pubDate>Sun, 16 Aug 2020 00:15:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/nil-channel-vs-closed-channel/</guid><description>The zero value of channel type is nil, and the send and receive operations on a nil channel will always block. Check the following example:
package main import &amp;#34;fmt&amp;#34; func main() { var ch chan int go func(c chan int) { for v := range c { fmt.Println(v) } }(ch) ch &amp;lt;- 1 } The running result is like this:
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send (nil chan)]: main.</description></item><item><title>Go - select</title><link>https://golang.k5kc.com/2020/08/16/3.select/</link><pubDate>Sun, 16 Aug 2020 00:12:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/3.select/</guid><description>Syntax
The select statement waits for multiple send or receive operations simultaneously.
// Blocks until there&amp;#39;s data available on ch1 or ch2 select { case &amp;lt;-ch1: fmt.Println(&amp;#34;Received from ch1&amp;#34;) case &amp;lt;-ch2: fmt.Println(&amp;#34;Received from ch2&amp;#34;) } The statement blocks as a whole until one of the operations becomes unblocked. If several cases can proceed, a single one of them will be chosen at random. Send and receive operations on a nil channel block forever.</description></item><item><title>Channels in Go</title><link>https://golang.k5kc.com/2020/08/16/2.channels/</link><pubDate>Sun, 16 Aug 2020 00:11:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/2.channels/</guid><description>Intro A go maxim or proverb is:
Do not communicate by sharing memory; instead, share memory by communicating.
So what is a channel?
A channel is a &amp;ldquo;typed&amp;rdquo; conduit (pipes) mechanism for goroutines to synchronize execution and communicate by passing values, using channel operator, &amp;lt;-. They are mechanism for communication between goroutines.
Syntax // can only be used to send float64s chan&amp;lt;- float64 // can only be used to receive ints &amp;lt;-chan int // can be used to send and receive values of type Dosa chan Dosa (The data flows in the direction of the arrow.</description></item></channel></rss>