Grokking Concurrency in Go
Vote

0% completed

​

Turning Off Select Cases with Nil Channels

A select case whose channel is nil is never ready. The case stays in the source code, but at run time the select ignores it. It waits only on the cases whose channels are not nil. Assigning nil to a channel variable is therefore a way to switch one case off, and assigning a real channel to it switches the case back on.

The rule follows directly from what Nil Channels showed: a send or a receive on a nil channel blocks forever. A blocking operation can never be the one that is ready, so select never chooses it

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content