2 ms·
> "Send and receive operations on a nil channel block forver." I literally can not imagine a worse behavior than my program blocking forever. Of all of the thi
by insanitybit 3y ago
> "Send and receive operations on a nil channel block forver."
I literally can not imagine a worse behavior than my program blocking forever. Of all of the things my program can do, short of giving remote code execution, blocking is literally the worst one I can think of.
- usrbinbash 3y agoGoroutines blocking is normal procedure in a a Go program. It also isn't a problem, unless my code is broken and allows all Goroutines to block simultaneously...in which case the runtime automatically terminates the program with a Deadlock-Panic. The behavior of nil-channels always blocking is on purpose, and tremendously useful in functions where we receive from multiple channels via `select`. It allows the function to easily manipulate it's own receive behavior simply by setting the local reference to the channel to `nil`. Since `selects` can also have `default`, the resulting functions don't have to block either.