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

select example in docs #2334

Closed
tungli opened this issue Feb 12, 2021 · 2 comments · Fixed by #2345
Closed

select example in docs #2334

tungli opened this issue Feb 12, 2021 · 2 comments · Fixed by #2345
Labels

Comments

@tungli
Copy link
Contributor

tungli commented Feb 12, 2021

I am an async noob but the 'simple example' in docs on select may be a bad example.
The example selects one of the futures:

let future1 = async { 1 };
let future2 = async { 2 };

The problem in this is that the computations are both Poll::Ready immediately (at least on my machine).
So the result of the select is always Either::Left, as I would expect from the implementation.
Therefore, the assert! in the example is misleading IMHO.

I would suggest being explicit about one future finishing first.
The simplest example I came up with is here.

@taiki-e
Copy link
Member

taiki-e commented Feb 13, 2021

I would accept a PR that improves this example.

@tungli
Copy link
Contributor Author

tungli commented Feb 14, 2021

Thanks @taiki-e! Created the PR #2345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants