FAQ
I considered it, I don't think its shorter and nested forms are harder to
read (thats why we have select).

Another problem is you are only considering minimal code I have posted what
if outchan takes 10mins to be ready other cases in outer select will not
execute until 10 mins pass.
On Friday, November 29, 2013 5:04:43 PM UTC+5:30, Dmitry Vyukov wrote:

The shorter form is:

loop:
for {
select {
case msg := <-inchan:
select {
case outchan <- msg:
case <-exitc:
break loop
}
case <-exitc:
break loop
}
}

http://play.golang.org/p/QblrW8OHiv





On Fri, Nov 29, 2013 at 3:30 PM, Niket Patel <nex...@gmail.com<javascript:>
wrote:
Hello,

I had case when I wanted to receive msg and and send message from inchan
to outchan in for-select. What I have did is following.

for {
select {
case msg = <-inchan:
case <-exitc:
exit = true
}

if exit {
break
}

select {
case outchan <- msg:
case <-exitc:
exit = true
}

if exit {
break
}
}

Any better way of doing it? *If language supports* then what I want can
be done as following, if inchan is ready to send and outchan ready to
receive then only it succeed.

for {
select {
case outchan <- inchan:
case <-exitc:
exit = true
}

if exit {
break
}
}

--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 11 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 29, '13 at 11:31a
activeNov 29, '13 at 12:30p
posts11
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase