I accept a done
channel in my function, which is nice for notifying callers when some async process has finished, if they care. This is very useful for writing unit tests for example.
If my caller doesn't need this functionality, is there an idiomatic way to pass a garbage channel, where all values sent to it are discarded immediately? I was initially surprised sending nil
didn't work (sending to nil blocks the sender). I can think of one gross implementation (like a goroutine always running that consumes from this channel), but I would love to write something like:
func myFunc(foo int, done chan bool) {
....
}
func main() {
myfunc(4, _)
}
Is there a simple way to accomplish this?