-
Notifications
You must be signed in to change notification settings - Fork 131
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
Enhancing docs for selector and channel, from feedback and careful testing #1137
Conversation
…sting uber-go#1131 was merged with some mostly-minor feedback to tackle, and this almost completes it. I have not yet run integration tests against signal channel behavior when closed, and I'm not yet entirely happy with the docs around signal channels in general, but I think this is a net improvement worth merging.
Receive(ctx Context, valuePtr interface{}) (more bool) | ||
Receive(ctx Context, valuePtr interface{}) (ok bool) |
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.
more consistent ok/more use across the board to match the go language reference's variable names.
// case i, more := <- chA: | ||
// if more { | ||
// counter += i | ||
// } | ||
// case i, more := <- chB: | ||
// if more { | ||
// counter += i | ||
// } | ||
// case x := <- chA: | ||
// counter += i | ||
// case y := <- chB: | ||
// counter += i |
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.
decided the ok/more/subtle difference in behavior wasn't worth addressing, as it made the code less normal and more complex.
for chans that are never closed and only contain the right values (no Receive errors), which is often the case in real code, both before and after behave identically.
// select { | ||
// case v, more := <- aChannel: ok = true | ||
// default: ok = false | ||
// case received, ok := <- aChannel: | ||
// if ok { | ||
// *valuePtr = received | ||
// } | ||
// more = ok | ||
// default: | ||
// // no value was read | ||
// ok = false | ||
// // but the read would have blocked, so the channel is not closed | ||
// more = true | ||
// } | ||
// | ||
// But if your output values are zero values, this is equivalent to a simpler form: | ||
// select { | ||
// case value, ok := <- aChannel: | ||
// more = ok | ||
// default: | ||
// // no value was read | ||
// ok = false | ||
// // but the read would have blocked, so the channel is not closed | ||
// more = true | ||
// } |
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 took a bit of time to nail down precisely :| it's a bit odd (I don't believe I've ever seen this kind of select statement in normal go code), but may be useful in some cases.
#1131 was merged with some mostly-minor feedback to tackle, and this almost completes it.
I have not yet run integration tests against signal channel behavior when closed, and I'm
not yet entirely happy with the docs around signal channels in general, but I think this
is a net improvement worth merging.