我的 Tornado 应用程序中有很多代码,如下所示:
@tornado.web.asynchronous
def get(self):
...
some_async_call(..., callback=self._step1)
def _step1(self, response):
...
some_async_call(..., callback=self._step2)
def _step2(self, response):
...
some_async_call(..., callback=self._finish_request)
def _finish_request(self, response):
...
self.write(something)
self.finish()
显然,内联回调会大大简化该代码,它看起来像:
@inlineCallbacks
@tornado.web.asynchronous
def get(self):
...
response = yield some_async_call(...)
...
response = yield some_async_call(...)
...
response = yield some_async_call(...)
...
self.write(something)
self.finish()
有没有办法在 Tornado 中进行内联回调或以其他方式简化代码?