In golang, when we need to wait for something to finish, we will use a channel.
example:
done := make(chan struct{})go func() { // ... close(done)}()<-done
But, in other way, chan interface{}
also works in this case.
So, what's the difference between chan struct{}
and chan interface{}
?
Example2:
done := make(chan struct{})go func() { // ... done <- struct{}{}}()<- done
In other case, if don't close channel in goroutine instead of send object to it.
There will create an object in goroutine, but if using chan interface{}
, can be send nil
object to channel.
Is it better to use chan struct{}
?