async enumeration - possible?
Ian Kelly
ian.g.kelly at gmail.com
Wed Nov 30 03:51:29 EST 2016
On Wed, Nov 30, 2016 at 1:29 AM, Frank Millman <frank at chagford.com> wrote:
> "Marko Rauhamaa" wrote in message news:87d1hd4d5k.fsf at elektro.pacujo.net...
>>
>>
>> One of the more useful ones might be:
>>
>> o = await anext(ait)
>>
>
> Definitely!
>
> But I found it easy to write my own -
>
> async def anext(aiter):
> return await aiter.__anext__()
Even simpler:
def anext(aiter):
return aiter.__anext__()
As a general rule, if the only await in a coroutine is immediately
prior to the return, then it doesn't need to be a coroutine. Just
return the thing it's awaiting so that the caller can be rid of the
middle man and await it directly.
More information about the Python-list
mailing list