Quantcast
Channel: Why using `chan struct{}` when wait something done not `chan interface{}`? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Jonathan Hall for Why using `chan struct{}` when wait something done not `chan interface{}`?

$
0
0

In your example of a 'done' channel, functionally speaking, the channel can be of literally any type, since no data is actually sent, and the channel is just used as a signaling mechanism. But in the interest of memory utilization, struct{} is the smallest data type available in Go, since it contains literally nothing, so no allocation necessary, which is why it's typically used in such scenarios.


Viewing all articles
Browse latest Browse all 3

Trending Articles