Get Untwisted
Untwisted is a variation of Twisted, exploiting features in Python 2.5, principally PEP 342. An advantage is more linear control flow
This is the same as using twisted.internet.defer.inlineCallbacks()
For example this commit achieves more linear control flow by exploiting PEP 342
Generally, asynchronous patterns like the following can be simplified like synchronous code,
def example():
# Two cases with common end statements, duplicated because of asynchronous
# call in one case
if case1:
def callback(result):
handleAsyncResult(result)
cleanup()
doSomeAsyncThing().then(callback)
else:
cleanup()
from untwisted import promise
@promise.resume
def example():
if case1:
result = yield doSomeAsyncThing()
handleAsyncResult(result)
cleanup()
By avoiding explicit callbacks, Untwisted achieves more linear, less "twisted" control flow
blog comments powered by Disqus