[Python-ideas] Maybe python should support arrow syntax for easier use async call ?
Andrew Barnert
abarnert at yahoo.com
Tue Sep 29 08:40:12 CEST 2015
From a quick glance, it looks like you're converting from coroutines back to callbacks just so you can partially hide the callbacks. Why not just stick with coroutines? Compare:
ping("http://baidu.com") | r ->
print(r.result())
print("something else")
r = await ping("http://baidu.com")
print(r.result())
print("something else")
And this doesn't require a new operator, or multiline lambdas, or a new operator that does its thing and also introduces a multiline lambda, or anything else.
Sent from my iPhone
> On Sep 28, 2015, at 23:31, 张沈鹏 <375956667 at qq.com> wrote:
>
> # The example works with tornado dev verison & python3.5
>
>
> import tornado
> from tornado.httpclient import AsyncHTTPClient
> from tornado.concurrent import Future
> from tornado.gen import convert_yielded
> from functools import wraps
>
> Future.__or__ = Future.add_done_callback
>
> def future(func):
> @wraps(func)
> def _(*args, **kwds):
> return convert_yielded(func(*args, **kwds))
> return _
>
>
>
> ##############
>
> @future
> async def ping(url):
> httpclient = AsyncHTTPClient()
> r = await httpclient.fetch(url)
> return r.body.decode('utf-8')
>
>
> ping("http://baidu.com") | (
> lambda r:print(r.result())
> )
>
> """
>
> Maybe python should support arrow syntax for easier use async call ?
>
> Now lambda only can write one line and must have parentheses ...
>
> FOR EXAMPLE
>
> ping("http://baidu.com") | r ->
> print(r.result())
> print("something else")
>
>
> I saw some discuss in https://wiki.python.org/moin/AlternateLambdaSyntax
> """
>
>
> tornado.ioloop.IOLoop.instance().start()
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150928/9f7067c4/attachment.html>
More information about the Python-ideas
mailing list