Thanks for your advice .. that's what I was looking for;)
Makes sense, I'll stick to your advice, kick the subclassing approach and the
stuff with the reordering version rcall().
That leaves "partial" and "lambda"
# Option 1 : prints 31
d2 = self.call("square", 6).addCallback(lambda res: self.call("sub", res,
5)).addCallback(self.show)
# Option 3 : prints -31
d4 = self.call("square", 6).addCallback(partial(self.call, "sub",
5)).addCallback(self.show)
Lambda is the most general, since it can insert the previous deferred's result
anywhere in the next call.
Partial only simulates append result to end of args of next call.
But lambda is also most verbose.
I'll sleep one night and then see if I document and endorse both or only lambda.
Obviously, I can't hinder anyone using both. Built in stuff.
Thanks again,
Tobias
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Glyph Lefkowitz
Gesendet: Dienstag, 23. August 2011 20:30
An: Twisted general discussion
Betreff: Re: [Twisted-Python] RPC design questions
On Aug 23, 2011, at 10:37 AM, Tobias Oberstein wrote:
class AutobahnDeferred(Deferred):
def call(self, *args):
return self.addCallback(self.protocol.rcall, *args)
Pro: most terse
Con: only supports single callback no errback
Con: subclassing in general is a bad idea. Subclassing Deferred is an even
worse idea. What if Deferred one day gets a new method called 'call' that does
something different? Your code would all break.
Anything why I shouldn't do?
Providing three different ways to do the same thing just so that you can use
different syntax depending on your mood is a recipe for making your code hard
to read. Pick one style, stick to it as much as possible - consistency is more
important than the benefits of any one particular style :).
(Except the subclassing one. Don't do that.)
-glyph
_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python