On Jan 30, 2016 7:13 AM, "Oscar Benjamin" <oscar.j.benja...@gmail.com> wrote: > > I haven't used PEP 492 yet but what about: > > async def aslice(asynciterator, end): > if end == 0: > return [] > items = [] > async for item in asynciterator: > items.append(item) > if len(items) == end: > break > return items > > rows = await aslice(cur, 2) > > AFAICT there's no generator-function-style syntax for writing an async > iterator so you'd have to make a class with the appropriate methods if > you wanted to be able to loop over aslice with async for.
Before you go any further with this, be sure to check out the aitertools third-party module. I haven't done anything with it myself, but it already claims to provide aiter and anext as well as async versions of everything in the standard itertools module. -- https://mail.python.org/mailman/listinfo/python-list