Python新手协程异步tornado.concurrent.Future如何理解,,官方例子:pythonf


官方例子:

pythonfrom tornado.concurrent import Futuredef async_fetch_future(url):    http_client = AsyncHTTPClient()    my_future = Future()    fetch_future = http_client.fetch(url)    fetch_future.add_done_callback(        lambda f: my_future.set_result(f.result()))    return my_future

什么协程,异步迷迷糊糊的!

完全不懂 my_future = Future() 为什么要生成个 Future 对象,最后又返回它!!已经痛苦了几天了!!大神来解救下我吧

你看漏这句了吧

my_future.set_result(f.result())

编橙之家文章,

评论关闭