By condition variable I mean sync.Cond

> On Feb 21, 2019, at 3:10 PM, Robert Engels <reng...@ix.netcom.com> wrote:
> 
> The proper solution is using a condition variable. You can handle the 
> proposed use case easily. There is no need for it to be specific to channels, 
> but you need another layer. 
> 
>> On Feb 21, 2019, at 2:49 PM, Burak Serdar <bser...@ieee.org> wrote:
>> 
>>> On Thu, Feb 21, 2019 at 1:44 PM Serhat Şevki Dinçer <jfcga...@gmail.com> 
>>> wrote:
>>> 
>>>> On Thursday, February 21, 2019 at 11:21:11 PM UTC+3, Jan Mercl wrote:
>>>> 
>>>> But then calling it or not has the exact same semantics. So what's it even 
>>>> good for?
>>> 
>>> 
>>> Let's take your case Jan:
>>> 
>>> func consumer() {
>>>   select {
>>>   case x := <-ch:
>>>       // received, consume x
>>>   default:
>>>       // empty ch, sleep or poll
>>>   }
>>> }
>>> 
>>> func producer() {
>>>   // produce x
>>>   select {
>>>   case ch <- x:
>>>       // send successful, on to a new x
>>>   default:
>>>       // full ch, sleep or poll, try to resend
>>>   }
>>> }
>>> 
>>> With the directives, you can do the following 'without disturbing the 
>>> processing pipeline' :
>>> 
>>> func consumer() {
>>>   for {
>>>       x := <-ch
>>>       // consume x
>>>   }
>>> }
>>> 
>>> func producer() {
>>>   for {
>>>       // produce x
>>>       ch <- x
>>>   }
>>> }
>>> 
>>> func observer1() {
>>>   for {
>>>       waitempty(ch)
>>>       // not enough producers, say, by some rate or counter, last empty 
>>> buffer time, empty buffer occorance etc.
>>>       // create anotherproducer
>>>      go producer() // could be up to a max number of producers
>>>   }
>>> }
>>> 
>>> func observer2() {
>>>   for {
>>>       waitfull(ch)
>>>       // not enough consumers, say, by some rate or counter etc.
>>>       // create another one
>>>       go consumer() // could be up to a max number of consumers
>>>   }
>>> }
>>> 
>>> I think that will be much more efficient, because you dont 'disturb the 
>>> processing pipeline'.
>> 
>> The problem with these operations is that they operate like flags that
>> tell if a certain threshold was reached. It doesn't tell how many
>> times that threshold was reached, or for how long that state lasted,
>> which is really what you need to do the things you want to do.
>> 
>>> 
>>> --
>>> 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.
>> 
>> -- 
>> 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.
> 
> -- 
> 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.

-- 
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