[Twisted-Python] A pseudo-deferred class that can be canceled
terry at jon.es
Mon Jan 4 23:45:56 EST 2010
As a final followup before bed...
I chose not to have a 'cancel' method on my class because that seemed
misleading. You're not really canceling anything. You're just asking that a
deferred that you got earlier be fired right now with a value of your
choosing. So I made 2 methods, and named them 'callback' and 'errback'.
The Subject above is reasonably accurate, it's like a pseudo-Deferred
class. Everyone works with regular deferreds, as usual, but if you know you
might want to "cancel" a deferred by firing it early, you can call the
call/errback methods on an instance of CancellableDeferred. Because the
deferred you're holding is not the one that was obtained by calling
self._f, it will fire immediately, which is surely part of the point of
cancellation. In other words, using the word "cancel" is just a convenient
short / casual description of what's actually being done.
I hope all these words are making things more clear, not less...
More information about the Twisted-Python