I did some digging, but didn't really find anything satisfactory, so I'm asking: are their any best practices or pros/cons for using return vs. runtime.Goexit for exiting a goroutine? So far, the only thing I came across in some testing is that if you're using waitgroups, it may not call the Done function.
Specific to the waitgroups (if interested): in some quick testing in a codebase I have, I create an anonymous function that executes as a goroutine to test a method that's supposed to run within a goroutine. I tried to use defer to have it call wg.Done() when the function called runtime.Goexit, but it didn't work. Not sure if this is intended or a bug.
Code example:
go func() {
wg.Add(1)
defer wg.Done()
// Function goes here...
}()