我有很多的代碼在我的龍捲風應用程序,它看起來是這樣的:相當於Tornado中的@inlineCallbacks?
@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中的代碼?
是的,這是自龍捲風版本'2.1'以來直接回答你的問題。 –
@NikolayFominyh:在2.0版本中我開始使用Tornado,升級時肯定錯過了「新增功能」;-) – vartec