2 ms·
How you handle err here? If you return, the go routines will leak
by javier2 1y ago
How you handle err here? If you return, the go routines will leak
- danenania 1y agoAh, good point—should be using a buffered channel to avoid that: errCh := make(chan error, len(urls))
- unsnap_biceps 1y agobuffered 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.
- danenania 1y ago> 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).