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