Golang Concepts: Nil Channels

In Go, channels are a core feature used for communication between goroutines. Channels are meant to be used for message sharing and hence when I encountered nil channels, I started to wonder why they were needed.

What are nil channels?

A nil channel in Go is a channel that has been declared but not initialized with a make statement, or explicitly set to nil.

A nil channel has the following properties:

  1. Receiving from a nil channel blocks forever.

--

--

Pratik Pandey - https://pratikpandey.substack.com

Senior Engineer with experience in designing and architecting large scale distributed systems.