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

Improve documentation for select!{} #6572

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Xiretza
Copy link

@Xiretza Xiretza commented May 19, 2024

Motivation

The lifecycle explanation for select!{} was a little bumpy, since the step where all <async expression>s are disabled was never actually encountered (step 4 always went back to step 3).

Solution

Reorder the steps in the explanation, and also reword them slightly to clarify control flow.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

Comment on lines +45 to 48
/// 5. Once an `<async expression>` returns a value, attempt to apply the value
/// to the provided `<pattern>`, if the pattern matches, evaluate `<handler>`
/// and return. If the pattern **does not** match, disable the current branch
/// and for the remainder of the current call to `select!`. Continue from step 3.
Copy link
Contributor

@Darksonn Darksonn May 19, 2024

Choose a reason for hiding this comment

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

Branches become disabled if the pattern doesn't match, which can in turn trigger the else branch. So it makes more sense to me to have the else branch below this.

Copy link
Author

Choose a reason for hiding this comment

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

The else branch can also be triggered before anything is polled if all the expressions are disabled via their condition, or if there are no expressions to begin with.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could perhaps list it twice, but I don't think it makes sense to remove the mention of else at the end.

Copy link
Author

Choose a reason for hiding this comment

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

At present, step 5 about else is never reached by following the lifecycle as written. Do you have any suggestions for rewording it to make it more correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can say "if all branches are disabled, go to step 6" and keep the step at the end?

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-macros Module: macros in the main Tokio crate labels May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-macros Module: macros in the main Tokio crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants