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 Volker for Why using `chan struct{}` when wait something done not `chan interface{}`?

$
0
0

The empty struct struct {} requires no memory. So if you have a channel with a large capacity you can save a few bytes by switching from make(chan bool, 1<<16) to make(struct {}, 1<<16). Using interface {} requires more space and is really strange here.

For an unbuffered done channel I think using struct {} is wrong as it is unclear. Using a simple chan bool is much more sensible. Using interface {} is completely wrong: It probably uses more space and is even less clear than struct {}.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>