| Store | Cart

Re: [Python-Dev] Importance of "async" keyword

From: Yury Selivanov <ysel...@gmail.com>
Fri, 26 Jun 2015 14:30:25 -0400

On 2015-06-26 1:40 PM, Ethan Furman wrote:
> 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. 

"business_new" should be defined with an 'async' keyword, that's where 
all the confusion came from:

   async def business_new():
      return await complex_calc(10)

Now, "business_new()" returns a coroutine (which will resolve to the 
result of "complex_calc" awaitable), "await business_new()" will return 
an int.


Yury
_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Sven R. Kunze Jun 24, 2015 06:14 pm
Yury Selivanov Jun 24, 2015 08:16 pm
Sven R. Kunze Jun 24, 2015 09:21 pm
Steven DAprano Jun 25, 2015 02:16 am
Sven R. Kunze Jun 25, 2015 03:55 pm
Andrew Svetlov Jun 25, 2015 07:11 pm
Nick Coghlan Jun 26, 2015 10:46 am
Sven R. Kunze Jun 26, 2015 01:48 pm
Ethan Furman Jun 26, 2015 02:20 pm
Chris Angelico Jun 26, 2015 02:31 pm
Paul Sokolovsky Jun 26, 2015 02:51 pm
Chris Angelico Jun 26, 2015 03:10 pm
R. David Murray Jun 26, 2015 04:07 pm
Chris Angelico Jun 26, 2015 04:20 pm
Yury Selivanov Jun 26, 2015 03:48 pm
Nick Coghlan Jun 26, 2015 05:29 pm
Ron Adam Jun 26, 2015 06:06 pm
Nick Coghlan Jun 27, 2015 01:42 am
Steve Dower Jun 26, 2015 03:47 pm
Ethan Furman Jun 26, 2015 05:40 pm
Yury Selivanov Jun 26, 2015 06:30 pm
Sven R. Kunze Jun 30, 2015 07:39 pm
Greg Ewing Jul 01, 2015 10:02 pm
Sven R. Kunze Jul 02, 2015 08:55 pm
Nick Coghlan Jul 03, 2015 09:40 am
Sven R. Kunze Jul 05, 2015 09:50 pm
Chris Angelico Jul 06, 2015 12:27 am
Nick Coghlan Jul 06, 2015 01:41 am
Sven R. Kunze Jul 06, 2015 08:08 pm
Nick Coghlan Jul 07, 2015 12:40 pm
Steve Dower Jul 06, 2015 02:03 am
Steve Dower Jun 26, 2015 07:03 pm
Nick Coghlan Jun 26, 2015 05:05 pm
Greg Ewing Jun 25, 2015 10:02 pm
Nick Coghlan Jun 26, 2015 10:52 am
Steven DAprano Jun 26, 2015 02:22 am
Messages in this thread