On Thursday, October 3, 2019 at 10:47:27 AM UTC-3, burak serdar wrote: > > On Thu, Oct 3, 2019 at 6:18 AM JuciÊ Andrade <oju...@gmail.com > <javascript:>> wrote: > > I use channels exactly that way and they work pretty well. > > Then you're paying some penalty for synchronization where the same > thing can be achieved without that penalty. > > Yes, indeed, but channels offer some significant advantages:
1. a division of labor between several goroutines is made possible without much effort. That can mean a lot, depending on how much complex is the logic involved in generating each value; 2. a possibly very complex state is preserved between each generated value (the execution stack); I would dare to say that a prime number generator is more of an exception, because the state to be preserved between calls is well understood. Now think about some evolving code, where you can't know beforehand how complex that will be some years from now. Channels are a safer bet. Anyway, you are correct: each use must be evaluated in it's pros an cons. You will see that in the vast majority of cases channels performance is more than enough. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/eb84a84c-be8d-4b81-8c5c-33cb09b70168%40googlegroups.com.