FAQ
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 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+unsubscribe@googlegroups.com.
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 | 2 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