lo
lo copied to clipboard
Allow restricting concurrency for parallel op's
Current implementation spawn as many go-routines as passed collection size (for example as passed to Map) method in parallel package. While this is perfectly okay to do for up to a few thousand go-routines, it could become problematic for larger values. For example, for a mapping operation that makes any networking call, this is almost equivalent to DOSsing the end service.
Suggestion is to allow configuring concurrency for such parallel operations. Default would be equal to runtime.NumCPU(), whereas, if anything <= 0 is specified, it would automatically switch to current default behavior. Anything greater than 0 would override previous behaviors specified.
Sample implementation with above in mind for Map method can be found here (this diff is against current implementation): https://www.diffchecker.com/4pLAUeMh
Let me know if this looks good. I can work on the PR.
Best wishes...
I implemented this in https://github.com/samber/lo/pull/37