On Wednesday, January 25, 2017 at 10:14:49 PM UTC+8, Jan Mercl wrote:
>
> On Wed, Jan 25, 2017 at 2:14 PM T L <tapi...@gmail.com <javascript:>> 
> wrote:
>
> > sometimes, I do want one case on a select block get selected even if 
> there are multiple unblocked cases.
> > For example, I don't want the dataCh case is selected if the stopCh and 
> the timer channel are unblocked:
>
>         select {
>         case <-priorityHigh:
>                 ...
>         default:
>                 select {
>                 case <-priorityLow:
>                         ...
>                 default:
>                         select {
>                         case <- priorityLowest:
>                                 ...
>                         }
>                 }
>         }
>
> -- 
>
> -j
>

It is really a solution. :)
Sometimes I use the following one:

select {
case <- stopCh:
    return
default:
}

select {
case <- stopCh:
    return
case value := <-dataCh:
}

But both our solutions are not less efficient than a priority select.

How about to enhance the select block syntax by assign a sort method for 
unblocked cases:

select (random | priority | ordered) {
case <- stopCh:
    return
case value := <-dataCh:
}

random: the current implementation
priority: by the case appearance order
ordered: one by one. (The last selected case will be the last candidate in 
the next round)


 

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to