Sounds like you are talking about managing the number of goroutines processing a channel of requests. If there are far too many requests, you want to start up more, if the queue is almost empty, you want to shut them down. You can achieve that by just looking at len(ch). If len(ch) > some threshold, make sure there are enough server goroutines. A server goroutine shut itself off, if it won't receive a request in some timeout period.
Even after reading through this thread I am not entirely clear what it is that you want. So I suggest clearly describe the *problem* you are trying to solve, as opposed to your particular solution. > On Feb 21, 2019, at 12:10 PM, Serhat Şevki Dinçer <jfcga...@gmail.com> wrote: > > Burak, I think you dont get the potential of the suggesred directives. > > You can be interested in waitepty(ch) for example when: > - you have direct control of who is pushing and pulling on it, and you know > what an empty buffer means > buffer could be "things to do or process", and you have a very easy-to-setup > observer to alert some routine that: > - you are out of job, or > - you have too many to process > > Also what you suggest as raciness is irrelevant: > > for { > x := <- ch { > // here, do you have a guarantee that you can put x back to the channel > ?? > } > } > > On Thursday, February 21, 2019 at 10:57:43 PM UTC+3, Burak Serdar wrote: > You can implement waitempty(ch) without a race condition. However, any > scenario in which you use waitempty(ch) would have a race condition, > because the moment it returns there is no guarantee on the state of > the channel. So in a piece of code like this: > > waitempty(ch) > post > > > the only guarantee you have is that when 'post' is running, ch was > empty at least once since waitempty was called. > > This code: > > for { > if waitempty(ch) { > ... > } > } > > is racy, because when you go into the if block, you have no idea how > many times ch was empty. > > -- > 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.