Allow prepare to be async like the normal get/post/... methods using the asynchronous decorator and having to call end_prepare.
Allow prepare to be async
I think it would be good to mention this feature in docstring of asynchronous decorator.
ps. there was many requests for this, I also faced with need of asynchronous prepare to get a redis db connection from pool (or establish it if there are no free connections)... now i have to add r = redis.get_locked_connection() in the beginning of every handlers get/post methods... (of course, it could be implemented in custom BaseHandler, but it looks bad to change API semantics in the application this way)
r = redis.get_locked_connection()
Added docstring to asynchronous decorator
Needs a test case. Tests should cover asynchronous prepare with both sync and async main methods, and also cover the case where the request is finished in prepare.
Maybe call the end method finish_prepare for consistency with finish? If I were starting from scratch I'd say that the @asynchronous decorator would call the decorated method with an extra callback argument, but I guess it's not worth making the behavior of prepare and get/post/etc different.
Added tests for async prepare
Added the test case.
I was just trying to mimic the @asynchronous behavior for prepare. I don't think it's worth having two different ways of treating async stuff.
Fixed test for python 3.2
Is there more input wrt this or will it be merged?
Sorry to leave this in the queue for so long. My thinking on asynchronous methods has evolved with the use of coroutines and Futures in 3.0. We can say now that a method is asynchronous if it returns a Future, and this means we don't have to give each potentially-asynchronous method its own finish method. The @asynchronous decorator already detects if its target returns a Future and runs finish() automatically (this is not just a convenience, but turns out to be necessary for error handling). I'd like to do something similar for prepare(), and potentially other methods.
Allow prepare to be asynchronous, and detect coroutines by their result.
The prepare method does not use the @asynchronous decorator, only
@gen.coroutine (or @return_future; it detects the Future return type).
The same logic is now available for the regular http verb methods as well.