[Twisted-Python] tee method in twisted.internet.defer.py ?

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Tue Nov 17 10:45:01 EST 2009

On 03:33 pm, terry at jon.es wrote:
>Is there a reason why the Deferred class doesn't have a tee method like 
>following (untested)?
>    def tee(self, d):
>        def _cb(arg):
>            d.callback(arg)
>            return arg
>        def _eb(arg):
>            d.errback(arg)
>            return arg
>        return self.addCallbacks(_cb, _eb)
>I suppose it could be called teeDeferred to correspond to 
>And I guess it's clear what it does and why it's quite different from
>chainDeferred. I at least would find it quite useful.

We implemented this 5 or 6 times at Divmod.  The most recent incarnation 
looks like this:


I admit that I'd probably find it about as useful as I find explicit 
calls to Deferred.chainDeferred - perhaps even slightly more so.  Though 
that's a low bar, I can't remember the last time I explicitly called 
chainDeferred; it's probably been a couple years.

Not to say it's a bad idea, but I don't think it's _obviously_ a great 
idea.  If someone wanted to contribute a documented, tested 
implementation, particularly with examples of common patterns that it 
simplifies, then you could probably convince someone to commit it.


More information about the Twisted-Python mailing list