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

Enhancing docs for selector and channel, from feedback and careful testing #1137

Merged
merged 1 commit into from
Oct 6, 2021

Conversation

Groxx
Copy link
Contributor

@Groxx Groxx commented Oct 5, 2021

#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.

@Groxx Groxx requested review from a team and longquanzheng October 5, 2021 05:54
@Groxx Groxx changed the title Enhancing docs for selector, from feedback and careful testing Enhancing docs for selector and channel, from feedback and careful testing Oct 5, 2021
…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.
Comment on lines -86 to +102
Receive(ctx Context, valuePtr interface{}) (more bool)
Receive(ctx Context, valuePtr interface{}) (ok bool)
Copy link
Contributor Author

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.

Comment on lines -146 to +198
// 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
Copy link
Contributor Author

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.

Comment on lines 135 to 157
// 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
// }
Copy link
Contributor Author

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.

@meiliang86 meiliang86 merged commit 338aad0 into uber-go:master Oct 6, 2021
@Groxx Groxx mentioned this pull request Nov 9, 2021
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.

None yet

3 participants