[Twisted-Python] Learning Twisted

Christopher Armstrong radix at twistedmatrix.com
Sat May 15 19:36:07 EDT 2004


Glyph Lefkowitz wrote:
> Jason Diamond wrote:
>> Also, it's not obvious to me how protocol implementors decide when to
>> have users override a method versus having them use callbacks. I know
>> I'm working on client code but knowing this might help me know how to
>> use their code. Is it a matter of personal preference? The ircLogBot
>> example didn't have any callbacks using deferreds but it looks like I
>> had no choice when using IMAP4Client.
> 
> It's not purely preference, but there is some overlap.  Generally, what 
> Deferreds are used for are when you've got some operation that happens 
> once, with one result: you want to delete a message, for example, and 
> get a notification when that deletion operation has completed.  Methods 
> on objects are used when you are doing something more persistent, for 
> example, connecting a client to a server - there is a potential for 
> success or failure of that one operation, true, but the more interesting 
> thing is the continuous stream of data being received from or sent to 
> the other side of the connection.

Also, the "request" vs "arbitrary events" distinction should be 
clarified: Deferreds (i.e., callbacks) are used when you want to expose 
an API that allows a request to be made for some operation to occur, and 
they'll get triggered when the operation is complete (or has errored). 
Methods to be overridden are there for when there's no 1:1 mapping of 
requests to responses, when these events can happen even without 
expecting them.

-- 
  Twisted | Christopher Armstrong: International Man of Twistery
   Radix  |          Release Manager,  Twisted Project
---------+           http://radix.twistedmatrix.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040515/e116b9a0/attachment.pgp 


More information about the Twisted-Python mailing list