Skip to content

Conversation

@Sypheos
Copy link
Member

@Sypheos Sypheos commented Dec 3, 2025

What does this PR do?

Add code examples and doc for the group package

What are the observable changes?

Good PR checklist

  • Title makes sense
  • Is against the correct branch
  • Only addresses one issue
  • Properly assigned
  • Added/updated tests
  • Added/updated documentation
  • Properly labeled

Additional Notes

based on the idea of @tgallice

https://github.com/upfluence/sql/compare/tg/doc?expand=1&short_path=b335630#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5


Note

Adds comprehensive documentation and example tests for group concurrency patterns (error, wait, throttled, limiter, typed, map).

  • Docs:
    • Add package-level documentation in group/group.go and detailed comments for ErrorGroup, ExitGroup, WaitGroup, ThrottledGroup, SharedThrottledGroup, TypedGroup, TypedRunner, MapRunner, and ExecuteMap.
    • Add docs for rate-limited wrapper in group/limiter/group.go.
  • Examples (tests):
    • group/err_group_example_test.go: examples for ExitGroup and ErrorGroup.
    • group/wait_group_example_test.go: example for WaitGroup collecting errors.
    • group/throttled_group_example_test.go: example for ThrottledGroup.
    • group/limiter/example_test.go: example for limiter.WrapGroup with rate limiter.
    • group/map_example_test.go: example for ExecuteMap.
    • group/typed_group_example_test.go: examples for TypedGroup and TypedRunner.
  • Minor:
    • Small cleanup in group/limiter/group.go (method formatting).

Written by Cursor Bugbot for commit 1c6cd16. This will update automatically on new commits. Configure here.

@Sypheos Sypheos requested a review from a team as a code owner December 3, 2025 10:44
@Sypheos Sypheos self-assigned this Dec 3, 2025
@Sypheos Sypheos requested review from karitham and lordteka and removed request for a team December 3, 2025 10:44
@karitham
Copy link
Contributor

karitham commented Dec 3, 2025

I really like the idea, but I would prefer if we'd put the examples in actual example functions (we have a language feature for it!) https://go.dev/blog/examples, instead of having these huge doc comments

Copy link
Member Author

Sypheos commented Dec 3, 2025

The problem with using function for examples is that they need to compile 🙃 . Also they only show up if you use the web interface, they won't show with just go doc <pkg> 😕. Not sure they show up either through go pls and not sure I'll think of going to the example file if you just want to lookup the code

Copy link
Contributor

@karitham karitham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, gopls does not expose them so we can only really see them by going to pkg.go.dev (in the case of this public package) or using go doc -http github.com/upfluence/pkg/group. Apparently goland does expose them but we can't really rely on that. LGTM I guess

Copy link
Member

@tgallice tgallice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could also add testable examples like alexis did in the errors pkg. https://github.com/upfluence/errors/pull/16/files#diff-d25f78641f53ef1d158d846c90d4162de71971d2311b554d7ae3a40b86456355
This as the benefice to ensure that examples are functional, AI trend to "invent" methods or functions ^^

Otherwise LGTM

// throttled := group.ThrottledGroup(g, 10) // max 10 concurrent
//
// for _, item := range items {
// item := item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to configure a agent for generated doc in order to add some rules to respect like use go version/style etc...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I already removed quite a lot 😢

// // Limit API calls to 50 per second
// rateLimiter := rate.NewLimiter(rate.Limit(50), 10)
//
// g := limiter.WrapGroup(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit duplicate with the global exemple L11

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I can remove the wrapping doc ?

@Sypheos
Copy link
Member Author

Sypheos commented Dec 3, 2025

I think we could also add testable examples like alexis did in the errors pkg. https://github.com/upfluence/errors/pull/16/files#diff-d25f78641f53ef1d158d846c90d4162de71971d2311b554d7ae3a40b86456355 This as the benefice to ensure that examples are functional, AI trend to "invent" methods or functions ^^

I didn't add them as they on purpose see. As for the hallucination, it's been a while since I faced any of them 🤔

@AlexisMontagne
Copy link
Member

@Sypheos the advantage i see with testable Example, is that it could be validated as part of the CI. As the code base evolves public symbol can have breakage in behavour or API, in that case having automated assertion of the validity of the example is pretty neat.

Bonus point: It increases the coverage!

group/group.go Outdated
// It receives a context.Context for cancellation and deadline support,
// and returns an error if the operation fails.
//
// Example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you provide example as testable example, should you remove them from here?

group/group.go Outdated
// until all scheduled runners complete, returning any errors according to
// the implementation's strategy.
type Group interface {
// Do schedule a Runner to execute concurrently.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was mistakenly reverted; 3rd person present of "to schedule" is "schedules"

Suggested change
// Do schedule a Runner to execute concurrently.
// Do schedules a Runner to execute concurrently.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar checker replaced by schedule because it though Do is a verb 🥲

@cursor
Copy link

cursor bot commented Dec 9, 2025

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on December 28.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@Sypheos Sypheos merged commit cc1bc8d into master Dec 10, 2025
4 checks passed
@Sypheos Sypheos deleted the sp/group-doc branch December 10, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants