lo icon indicating copy to clipboard operation
lo copied to clipboard

Allow restricting concurrency for parallel op's

Open freakynit opened this issue 3 years ago • 1 comments

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...

freakynit avatar Mar 06 '22 13:03 freakynit

I implemented this in https://github.com/samber/lo/pull/37

Azer0s avatar Mar 16 '22 23:03 Azer0s