[Python-Dev] Importance of "async" keyword

Ethan Furman ethan at stoneleaf.us
Fri Jun 26 19:40:37 CEST 2015


On 06/26/2015 08:47 AM, Steve Dower wrote:
> On 06/26/2015 06:48 AM, Sven R. Kunze wrote:
>
>> def business():
>>       return complex_calc(5)
>>
>> def business_new()
>>       return await complex_calc(10)

> Assuming "async def business_new" (to avoid the syntax error), there's no difference between those functions or the one they're calling:
>
> * "complex_calc" returns an awaitable object that, after you've awaited it, will result in an int.
> * "business" returns the return value of "complex_calc", which is an awaitable object that, after you've awaited it, will result in an int.
> * "business_new" returns an awaitable object that, after you've awaited it, will result in an int.
>
> In all three of these cases, the result is the same. The fact that the awaitable object returned from any of them is implemented by a coroutine isn't important (in the same way that an iterable object may be implemented by a generator, but it's really irrelevant).

What?  Shouldn't 'business_new' return the int?  It did await, after all.

--
~Ethan~


More information about the Python-Dev mailing list