2 ms·
If channels are the wrong way to do things in Golang, what is the right way?
by dingdingdang 1y ago
If channels are the wrong way to do things in Golang, what is the right way?
- fpoling 1y agoIn Go in many cases channels are unavoidable due to API. As already was pointed out in other threads a good rule of thumb is not to use them in public method signatures. The valid use case for channels is to signal to consumer via channel close in Context.Done() style that something is ready that then can be fetched using separated API. Then if you need to serialize access, just use locks. WorkGroup can replace channels in surprisingly many cases. A message passing queue with priorities implemented on top of mutexes/signals can be used in many cases that require complex interactions between many components.
- dingdingdang 1y agoCheers for clear summary, I take it you mean sync.WaitGroup and not WorkGroup? As a beginner I started up with WaitGroup usage years ago since it was more intuitive to me.. worked fine afaict.