Quantcast
Viewing latest article 1
Browse Latest Browse All 3

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

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 latest article 1
Browse Latest Browse All 3

Trending Articles