-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
updated race example to use variable assignment to track winner instead of memory channel #1978
Conversation
…ad of memory channel.
Codecov Report
@@ Coverage Diff @@
## master #1978 +/- ##
==========================================
- Coverage 99.58% 99.54% -0.05%
==========================================
Files 114 114
Lines 14627 14627
Branches 1119 1119
==========================================
- Hits 14567 14561 -6
- Misses 43 45 +2
- Partials 17 21 +4
|
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 the PR, @kbiggers! (Caught a minor issue in the code and left a suggested fix, but) the main change here makes sense to me: Folks new to Trio seem to reach for memory channels more often than more experienced users do, and it's interesting to learn that this particular section of the documentation was partly responsible for this for you and others, especially since it's currently the top result for e.g. https://trio.readthedocs.io/en/stable/search.html?q=race
Looks like these docs were last touched 3 years ago, so I wonder if we have a better understanding of Trionic style now, or if @njsmith thinks these docs should actually stay as-written. Looks like this was discussed in Gitter and @njsmith approved, nice. Sorry I missed that!
docs/source/reference-core.rst
Outdated
await send_channel.send(await async_fn()) | ||
async def jockey(async_fn, cancel_scope): | ||
nonlocal winner | ||
await winner = async_fn() |
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.
await winner = async_fn() | |
winner = await async_fn() |
ah good catch about the await, I'll fix that! |
Failed test is spurious, caused by #1785 (comment) Anyway, looks good, so thanks! Hopefully this will make the next reader's life just a little bit easier. |
Hey @kbiggers, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂 If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:
If you want to read more, here's the relevant section in our contributing guide. Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you. If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out! |
When I was first reading through the docs for trio I was a bit thrown off by the use of a memory channel in the race example. Since the memory channel itself is not what is meant to be demonstrated here, I think it might be better to remove it in favor of simple variable assignment. Another plus of this is it demonstrates the ability to use nurseries themselves for waiting.
I may be alone in being confused with the memory channel, so please let me know if you prefer it the original way, and also let me know if you have any questions about this.
Thanks!