Re: [Python-ideas] Replacing Infinite while Loops with an Iterator: async edition

2018-06-24 Thread jab
Yes, exactly. Wouldn't that be a useful built-in? (And, is this really the first time this idea is being discussed?) Thanks, Josh On Saturday, June 23, 2018 at 9:12:35 PM UTC-4, Nathaniel Smith wrote: > > On Sat, Jun 23, 2018 at 5:58 PM, Greg Ewing > wrote: > > j...@math.brown.edu wrote: > >

Re: [Python-ideas] Replacing Infinite while Loops with an Iterator: async edition

2018-06-23 Thread Nathaniel Smith
On Sat, Jun 23, 2018 at 5:58 PM, Greg Ewing wrote: > j...@math.brown.edu wrote: >> >> it would be nice if we could write an async version of this, as in ``async >> for chunk in aiter(...)``. > > The time machine seems to have taken care of this: > > https://docs.python.org/3.6/reference/compound_s

Re: [Python-ideas] Replacing Infinite while Loops with an Iterator: async edition

2018-06-23 Thread Greg Ewing
j...@math.brown.edu wrote: it would be nice if we could write an async version of this, as in ``async for chunk in aiter(...)``. The time machine seems to have taken care of this: https://docs.python.org/3.6/reference/compound_stmts.html#the-async-for-statement -- Greg ___

[Python-ideas] Replacing Infinite while Loops with an Iterator: async edition

2018-06-23 Thread jab
I first learned the ``for chunk in iter(lambda: sock.recv(N), b'')`` trick from page 138 of Dave Beazley’s fantastic Python Cookbook (“4.16. Replacing Infinite while Loops with an Iterator”), and never looked back. When I started to play with consuming sockets asynchronously, it occurred to me tha