a := make(chan struct{})
Such this, go channel take empty struct as input. Can this input be anything?
thanks.
No: it can be an empty struct (struct{}{}
), not "anything"
To be "anything", you would need interface{}
.
As I explain in "Go Golang : anonymous struct and empty struct", an empty struct is useful to pass an object of size... 0! It is a good way to signal the completion that something has happened.
struct{}
is much like the unit type in other languages; it only has one value with no information. The values you get from such a channel would contain no information, but such a channel could be used for signalling when some event happened. A goroutine receiving from that channel would wake up whenever something is sent to it.