如何扭曲资源对象render_Post返回一定的价值有些推迟
问题描述:
后,我应该写一些代码,像这样:如何扭曲资源对象render_Post返回一定的价值有些推迟
class SomePage(Resource):
def render_GET(self, request):
d = DoSomeQuery()
# if d run success
# return "success"
# if d fails
# return "fail"
我的意思是render_GET函数的返回值取决于延迟的结果。
我该怎么做?
答
补充一点:
d.addCallbacks(lambda _: "success",
lambda _: "fail")
d.addCallback(request.write)
d.addBoth(lambda _: request.finish())
return server.NOT_DONE_YET