<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">This draft proposal for async generators in ECMAScript 7 may be interesting reading to those who haven’t already: <a href="https://github.com/jhusain/asyncgenerator" class="">https://github.com/jhusain/asyncgenerator</a></div><div class=""><br class=""></div><div class="">This talk also has some good ideas about them, though the interesting stuff about using async generator syntax is all on the last slide, and not really explained: <a href="https://www.youtube.com/watch?v=gawmdhCNy-A" class="">https://www.youtube.com/watch?v=gawmdhCNy-A</a></div><br class=""><div><blockquote type="cite" class=""><div class="">On May 5, 2015, at 3:55 PM, Guido van Rossum <<a href="mailto:guido@python.org" class="">guido@python.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">One small clarification:<br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, May 5, 2015 at 12:40 PM, Jim J. Jewett <span dir="ltr" class=""><<a href="mailto:jimjjewett@gmail.com" target="_blank" class="">jimjjewett@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
</span>[...] but I don't understand how this limitation works with things like a<br class="">
per-line file iterator that might need to wait for the file to<br class="">
be initially opened.<br clear="all" class=""></blockquote><div class=""><br class=""></div><div class=""> Note that PEP 492 makes it syntactically impossible to use a coroutine function to implement an iterator using yield; this is because the generator machinery is needed to implement the coroutine machinery. However, the PEP allows the creation of asynchronous iterators using classes that implement __aiter__ and __anext__. Any blocking you need to do can happen in either of those. You just use `async for` to iterate over such an "asynchronous stream".<br class=""><br class=""></div><div class="">(There's an issue with actually implementing an asynchronous stream mapped to a disk file, because I/O multiplexing primitives like select() don't actually support waiting for disk files -- but this is an unrelated problem, and asynchronous streams are useful to handle I/O to/from network connections, subprocesses (pipes) or local RPC connections. Checkout the <a href="https://docs.python.org/3/library/asyncio-stream.html" class="">streams</a> and <a href="https://docs.python.org/3/library/asyncio-subprocess.html" class="">subprocess</a> submodules of the asyncio package. These streams would be great candidates for adding __aiter__/__anext__ to support async for-loops, so the idiom for iterating over them can once again closely resemble the idiom for iterating over regular (synchronous) streams using for-loops.)<br class=""></div></div><br class="">-- <br class=""><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank" class="">python.org/~guido</a>)</div>
</div></div>
_______________________________________________<br class="">Python-Dev mailing list<br class=""><a href="mailto:Python-Dev@python.org" class="">Python-Dev@python.org</a><br class="">https://mail.python.org/mailman/listinfo/python-dev<br class="">Unsubscribe: https://mail.python.org/mailman/options/python-dev/ryan%40ryanhiebert.com<br class=""></div></blockquote></div><br class=""></body></html>