Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #126 +/- ##
==========================================
- Coverage 99.31% 98.94% -0.38%
==========================================
Files 12 12
Lines 441 474 +33
==========================================
+ Hits 438 469 +31
- Misses 3 4 +1
- Partials 0 1 +1 ☔ View full report in Codecov by Sentry. |
| type resultAggregator[T any] struct { | ||
| mu sync.Mutex | ||
| len int | ||
| results []T | ||
| errored []int | ||
| } |
There was a problem hiding this comment.
The changes to resultAggregator are central to this PR.
Summary:
- Add a
nextIndexmethod that makes it possible to reserve a slot in the result slice - Change the
addmethod tosave, which also takes an the index fromnextIndexand whether the result errored - Add a
collectmethod that respects theWithCollectErroredoption by filtering out errored results.
bobheadxi
left a comment
There was a problem hiding this comment.
Nice, LGTM - this does add an extra set of lock/unlock on the mutex, though I imagine it doesn't make much difference in practice
Yes, it does. It would be possible to use an atomic integer for reserving a slot, but it adds more complexity of the implementation and I wouldn't expect these to be a high-contention since in most cases, the task being done in a goroutine is large. We can do some benchmarking and improve perf later if the difference turns out to be significant. |
|
Any plans to tag a new release with this change? |
This PR makes the order of results in a
Result.*Pooldeterministic so that the order of the result slice corresponds with the order of tasks submitted. As an example of why this would be useful, it makes it easy to rewriteiter.Mapin terms ofResultPool. Additionally, it's a generally nice and intuitive property to be able to match the index of the result slice with the index of the input slice.Comments inline.