btw waitempty(ch) does not return any value, and it does not (have to) guarantee that ch stays empty when it returns..
On Thursday, February 21, 2019 at 11:10:45 PM UTC+3, Serhat Şevki Dinçer 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.