Showing content from http://mail.python.org/pipermail/python-dev/attachments/20171127/0eeeb9e2/attachment.html below:
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Nov 26, 2017 at 7:43 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Honestly, this is one of Python's biggest problems when it comes to<br>
async functions. I don't know the answer to that question, and I don't<br>
know where in the docs I'd go looking for it. In JavaScript, async<br>
functions are built on top of promises, so you can just say "well, you<br>
return a promise, tada". But in Python, this isn't well documented.<br>
Snooping the source code for asyncio.sleep() shows that it uses<br>
@coroutine and yield, and I have no idea what magic @coroutine does,<br>
nor how you'd use it without yield.<br></blockquote><div><br></div><div>The source for sleep() isn't very helpful -- e.g. @coroutine is mostly a backwards compatibility thing. The heart of it is that it creates a Future and schedules a callback at a later time to complete that Future and then awaits it -- this gives control back to the scheduler and when the callback has made the Future complete, the coroutine will (eventually) be resumed.<br></div><div><br></div><div>(JS Promises are equivalent to Futures, but the event loop in JS is more built in so things feel more natural there.)<br></div><div><br></div><div>What we need here is not just documentation of how it works, but a good tutorial showing a pattern for writing ad-hoc event loops using a simple Future class. A good example would be some kind of parser (similar to Nathaniel's websockets example). I wish I had the time to write this example -- I have some interest in parsers that work this way (in fact I think most parsers can and probably should be written this way). But I've got a huge list of things to do already... :-(<br></div></div><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4