News for hackers. Stuff that matters.
Re:Golang: Know Your 'Nil' by tedunangst on Tuesday March 30, 2021 @01:55PM (#26637926)
I think the question is when would it be useful outside of select. Once you block on nil channel, there's no way to unblock, which doesn't seem helpful.
Re:Golang: Know Your 'Nil' by jrockway on Tuesday March 30, 2021 @02:19PM (#26638227)
Such is the danger of blocking indefinitely. I think every Go programmer's first concurrent app eventually crashes because it runs out of memory, memory used by goroutines that are waiting for an answer that will never come. When you write "foo := <-ch", you're saying "I am willing to wait forever for an answer". Unfortunately, actual computers in the real world don't have the resources to wait forever.

Honestly, I see the ability to block indefinitely as a bug in the language. An improved language would probably "result, err := <(ctx)- ch", i.e. make it impossible to block without something bounding the duration of the block. (Also kill sync.Mutex. 100% of Go concurrency bugs are from people mixing mutexes and channels.)

(As an alternative, the runtime could be smarter about goroutines that have blocked forever. I am not sure exactly what it would look like, but the hypothetical first Go program I talk about above would probably be saved by something that killed goroutines that were waiting for a message from a TCP connection that is long gone. I think if it were easy to do right, it would have been done, though.)

Re:Golang: Know Your 'Nil' by konart on Tuesday March 30, 2021 @02:18PM (#26638214)
They only case I can think of right away is some kind of process that should not die after the execution and wait until the user kills it by hand after reading through execution report.