-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 guidance on goroutine lifecycle management #158
Conversation
This is mostly an RFC based on some internal discussions. In general, we prefer for goroutines to have well-managed lifecycles. No uncontrolled background work that cannot be stopped. This change tries to distill some of the guidance around it into a style guide entry. It's not super comprehensive, but it tries to cover some of the guiding principles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this, I've been thinking about this same recommendation after leaving multiple reviews in a similar vein!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks @abhinav!
Thanks for the feedback, all. Besides the minor comments, I've made the following changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff!
style.md
Outdated
stop := make(chan struct{}) // tells the goroutine to stop | ||
done := make(chan struct{}) // tells us that the goroutine exited |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these intentionally ungrouped (e.g. to minimize example LOC)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, yeah. Good catch.
This is mostly an RFC based on some internal discussions.
In general, we prefer for goroutines to have well-managed lifecycles.
No uncontrolled background work that cannot be stopped.
This change tries to distill some of the guidance around it into a style
guide entry.
It's not super comprehensive, but it tries to cover some of the guiding
principles.
Rendered: /~https://github.com/uber-go/guide/blob/goroutines/style.md#dont-fire-and-forget-goroutines