Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context awareness #5

Merged
merged 2 commits into from
Aug 22, 2018
Merged

Add context awareness #5

merged 2 commits into from
Aug 22, 2018

Conversation

hstern
Copy link
Contributor

@hstern hstern commented Aug 15, 2018

This allows for the Add call to be interrupted by context cancellation.

This allows for the Add call to be interrupted by context cancellation.
@remeh
Copy link
Owner

remeh commented Aug 16, 2018

Hello Henry, thanks for the pull-request! I'll check this out soon.

Copy link
Owner

@remeh remeh left a comment

Choose a reason for hiding this comment

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

Hi Henry,

I think it would be better to do it another way: simply by adding a method called AddWithContext(ctx context.Context).

The Go documentation mentions that it is not a good practice to store a context inside a struct (see https://golang.org/pkg/context/), it would also be more idiomatic as many packages of the standard library have chosen this solution. On top of that, it would avoid having to return an error/nil in the method Add().

//
// See sync.WaitGroup documentation for more information.
func (s *SizedWaitGroup) Add() {
s.current <- struct{}{}
func (s *SizedWaitGroup) Add() error {

This comment was marked as outdated.

@hstern
Copy link
Contributor Author

hstern commented Aug 22, 2018

@remeh There are lots of modules in the standard go library that store contexts (eg. http.Request) but you're right that it's poor practice. Is 0da8c97 more to your liking?

@remeh
Copy link
Owner

remeh commented Aug 22, 2018

Hi @hstern , that looks perfect! Thank you for your contribution!

@remeh remeh merged commit 5e7302b into remeh:master Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants