On 2/9/06, Valentino Volonghi aka Dialtone <dialtone at divmod.com> wrote: > Let's consider this piece of code (actual code that works today and uses > twisted for convenience): > > def do_stuff(result): > if result == 'Initial Value': > d2 = work_on_result_and_return_a_deferred(result) > d2.addCallback(println) > return d2 > return 'No work on result' > > def println(something): > print something > > d1 = some_operation_that_results_in_a_deferred() > d1.addCallback(do_stuff) > d1.addCallback(lambda _: reactor.stop()) > > reactor.run() PEP 342 provides a much better alternative: def do_stuff(): result = (yield some_operation()) something = (yield work_on_result(result)) print something reactor.stop() # Maybe unnecessary? reactor.run(do_stuff()) Apparantly it's already been applied to Python 2.5: http://www.python.org/dev/doc/devel/whatsnew/node4.html Now that may not be the exact syntax that Twisted provides, but the point is that the layout (and the top-to-bottom execution order) is possible. -- Adam Olsen, aka Rhamphoryncus
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4