2012-08-28 22:56:21 +02:00
|
|
|
import types
|
|
|
|
|
|
|
|
class TornadoAsyncException(Exception): pass
|
|
|
|
|
|
|
|
class _DefGen_Return(BaseException):
|
|
|
|
def __init__(self, value):
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def returnResponse(value):
|
|
|
|
raise _DefGen_Return(value)
|
|
|
|
|
|
|
|
def asynchronous(method):
|
|
|
|
def wrapper(request, *args, **kwargs):
|
|
|
|
try:
|
|
|
|
v = method(request, request._tornado_handler, *args, **kwargs)
|
|
|
|
if v == None or type(v) == types.GeneratorType:
|
2012-09-05 17:23:58 +02:00
|
|
|
raise TornadoAsyncException
|
2012-08-28 22:56:21 +02:00
|
|
|
except _DefGen_Return, e:
|
|
|
|
request._tornado_handler.finish(e.value.content)
|
|
|
|
return v
|
|
|
|
return wrapper
|