Skip to content

fix: ResultErrorPool.Wait clips results after first error - #160

Closed
Yanhu007 wants to merge 1 commit into
sourcegraph:mainfrom
Yanhu007:fix/result-pool-collect-missing-tail
Closed

Yanhu007 wants to merge 1 commit into
sourcegraph:mainfrom
Yanhu007:fix/result-pool-collect-missing-tail

Conversation

@Yanhu007

Copy link
Copy Markdown

Fixes #156

Problem

collect() filters out errored results but never appends results after the last errored index. For example:

p := pool.NewWithResults[int]().WithErrors()
p.Go(func() (int, error) { return 1, nil })
p.Go(func() (int, error) { return 0, errors.New("err") })
p.Go(func() (int, error) { return 3, nil })
results, _ := p.Wait()
// Got:    [1]
// Expect: [1, 3]

The loop iterates over errored indices and appends slices between errors, but after the loop ends it doesn't append the remaining tail from lastErr+1 to the end.

Fix

After the filtering loop, append r.results[lastErr+1:] if there are remaining results.

All existing tests pass.

The collect function filters out errored results but doesn't
append results after the last errored index. For example, with
results [1, err, 3], only [1] is returned instead of [1, 3].

Add the missing tail append after the filtering loop.

Fixes sourcegraph#156
@Yanhu007

Copy link
Copy Markdown
Author

Superseded by #162 which has a cleaner fix. Closing this one.

@Yanhu007 Yanhu007 closed this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant