[Twisted-Python] Deferreds
    Andrew Bennetts 
    andrew-twisted at puzzling.org
       
    Thu Apr  4 17:35:00 MST 2002
    
    
  
I feel silly replying to myself, but anyway...
On Fri, Apr 05, 2002 at 10:06:46AM +1000, Andrew Bennetts wrote:
> I've been thinking about Deferreds lately, and I think they are lacking
I've been chatting about Deferreds on IRC with Drew, and he's made me
realise a few more things:
  1) There's currently no way to cancel a Deferred
  2) It looks like you can fire a Deferred multiple times.
You could workaround 1 by calling the errback if it wasn't for 2.
Point 2 surprised me; I expected Deferreds to be single shot (though I can
imagine that a multi-use Deferred would be ideal for some situations).
----
class AlreadyCalledError(Exception):
    pass
class OneShotDeferred(Deferred):
    def _runCallbacks(self, result, isError):
        if self.called:
            raise AlreadyCalledError
        Deferred._runCallbacks(self, result, isError)
----
But I think that this behaviour should probably be the default anyway (while
still providing the old behaviour).
-Andrew.
    
    
More information about the Twisted-Python
mailing list