[Twisted-Python] Syntactic sugar for deferreds

Konrads Smelkovs konrads at smelkovs.com
Mon Dec 7 09:50:57 EST 2009


One project I had a look at had this nice syntactic sugar for async function

>>> event_one() | event_two() | event_three()

I think this could be an interesting alternative to addCallback or yield. I
propose the following syntax

# get deferred with one () and two () chained as callbacks, equivalent to
>>> d = Deferred() | one | two

# Equivalent to d=Deferred().addCallback(one).addErrback(two)
>>> d = Deferred() | one ^ two

and finally:
# d=Deferred().addBoth(one,two)
>>> d = Deferred() & (one,two)

This could make use of currying/
Konrads Smelkovs
Applied IT sorcery.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20091207/b6a9e15c/attachment-0001.htm 

More information about the Twisted-Python mailing list