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
sync: Export Waitgroup.counter and WaitGroup.waiters #7202
Labels
Comments
I don't get it why this will make this API more complex. To have my own counter I'll need to duplicate something that is already inside the API, but not exported. Things can become a bit "duplicated": http://play.golang.org/p/sr3MCVk5Rw |
Any additions to an API make it more complex, as a matter of definition. The Go 1 guarantee (http://golang.org/doc/go1compat) means that if we add exported fields to WaitGroup, we are promising to maintain those fields forever. That would limit our ability to change WaitGroup in the future. |
I would like to: - instrument/monitor the application - be able to safely abort every blocked WaitGroup.Wait() I know these can be achieved through other ways, but looking at Go source I had this idea to avoid the necessity of having variables to store the same counters. If you have plans to rewrite WaitGroup, please, consider these ideas. We could have methods instead of just exporting those fields (eg WaitGroup.Counter(), WaitGroup.Waiters()), so future changes in the implementation could be done without deprecations in the API. |
WaitGroup.Wait does not return an error, so I am not sure how it can be safely aborted The caller won't be able to understand whether it's aborted or not WaitGroup is intended to simple cases, for more complex cases (which there are much much more than just the 2 you described), there are channels/select, or mutexes/condvars and atomic operations. E.g. here how you can have abortable wait with select: func waitWithTimeout(c chan struct{}, n int, d time.Duration) bool { t := time.After(d) for i := 0; i < n; i++ { select { case <-c: case <-t: return false } } return true } |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: