Skip to content

If the function returns a future, handle things asynchronously#12

Open
spanezz wants to merge 3 commits intojoshmarshall:masterfrom
spanezz:master
Open

If the function returns a future, handle things asynchronously#12
spanezz wants to merge 3 commits intojoshmarshall:masterfrom
spanezz:master

Conversation

@spanezz
Copy link
Copy Markdown
Contributor

@spanezz spanezz commented Feb 6, 2015

Currently I can use @async to make a xmlrpc server method asynchronous, but with tornado.gen and friends, I tried to make it so that I could use a @gen.coroutine instead. The first step was to make it so that if an xmlrpc method returns a Future, it is run asynchronously and its result is returned transparently.

Unfortunately, @gen.coroutines still cannot be used transparently, because the wrapper that they create confuses tornadorpc's getcallargs. Still, I find this change quite handy.

With regards to using gen.coroutines, at least now I can do this:

class RpcHandler(XMLRPCHandler):
    def foo(self):
        @gen.coroutine
        def run():
            result1 = yield something(1, 2, 3)
            result2 = yield somethingelse(3, 4, 5)
            raise gen.Return(result1 + result2)
        return run()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants