Comment by javier2
How you handle err here? If you return, the go routines will leak
How you handle err here? If you return, the go routines will leak
buffered channels won't help here. That's just how many results can be buffered before the remaining results can be added to the channel. It doesn't wait until all of them are done before returning a result to the consumer.
> It doesn't wait until all of them are done before returning a result to the consumer.
Right, but it prevents goroutine leaks. In these situations I'm usually fine with bailing on the first error, but I grant that's not always desirable. If it's not, I would collect and join errors and return those along with partial results (if those are useful).
Ah, good point—should be using a buffered channel to avoid that: