4 ms·
I find the channels to be the most confusing thing in Go. What happens when you write to a closed channel? What about a blocked one? What if you read from a cl
by eknkc 6y ago
I find the channels to be the most confusing thing in Go.
What happens when you write to a closed channel? What about a blocked one? What if you read from a closed one. Can you close a closed channel? Does that panic? What was the non blocking read? What about write?
Fuck that, I use the sync Mutex primitives and good old slices instead.
- Groxx 6y ago+1 to this. I'd say nearly half of the channel code I've encountered in "real code" has had severe flaws when things don't align perfectly. They don't have data races, in that the race detector will give it a thumbs-up, but they do have semantic races leading to deadlocks, misbehavior, dropped data, etc. They generally work fine when they're not under heavy load / contention, so they aren't noticed until they collapse. Mutex code though? 90% correct, easily. It's often dramatically simpler to make correct, especially when more than one construct is needed, or nearly anywhere with error handling. (`defer` is quite nice for locks)