On Sat, Nov 25, 2017 at 3:37 PM, Guido van Rossum <guido@python.org> wrote:
> Maybe you didn't realize async/await don't need an event loop? Driving an
> async/await-based coroutine is just as simple as driving a yield-from-based
> one (`await` does exactly the same thing as `yield from`).
On Sun, Nov 26, 2017 at 12:29 PM, Nathaniel Smith <njs@pobox.com> wrote:Technically anything you can write with yield/yield from could also be
written using async/await and vice-versa, but I think it's actually
nice to have both in the language.
In [1]: from itertools import takewhileIn [2]: def injectable_fib(a=1, b=2):...: while True:...: new = yield a...: if new is not None:...: a, b = new...: a, b = b, a+b...:In [3]: f = injectable_fib()In [4]: list(takewhile(lambda x: x<200, f))Out[4]: [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]In [5]: f.send((100,200))Out[5]: 200In [6]: list(takewhile(lambda x: x<1000, f))Out[6]: [300, 500, 800]
In [9]: async def atakewhile(pred, coro):...: l = []...: async for x in coro:...: if pred(x):...: return l...: l.append(x)
async def afib_injectable():