[Twisted-Python] ANN: deferred howto/tutorial

Andrew Bennetts andrew-twisted at puzzling.org
Sat Oct 23 16:06:50 MDT 2004


On Sat, Oct 23, 2004 at 05:44:35PM -0400, Stephen Waterbury wrote:
> Mary Gardiner wrote:
> >On Sat, Oct 23, 2004, Andrew Bennetts wrote:
> >
> >>The obvious disadvantage compared to your style is the loss of the
> >>direct visual association of which callbacks relate to which
> >>deferreds.  I'd be moderately interested in hearing how other people
> >>cope with that
> >
> >I find it's a problem when you start chaining deferreds by returning
> >deferred from callbacks: not so much that it's difficult to find out
> >where the callback is added, but that there's no visual representation
> >that corresponds to the "nesting" of the callbacks.
> 
> I like to think of it as the asynchronous form of
> "pipes and filters", so chaining deferreds seems quite
> logical to me.

That's how I think of it too.  However, if you layout code like stefan does
(placing callback definitions inside the other function definitions), then
you will get visually nested callbacks.  I suppose that's another argument
against defining callbacks within functions ;)

[Sidenote: in my usual mental model, "nesting" would be something you do
with deferreds, rather than callbacks, i.e. it's what happens when a
callback of one deferred returns some other deferred.  And then there's
"chaining" Deferreds with the "chainDeferred" method, which I always have to
read the implementation of to figure out which way round I need to call it.]

-Andrew.





More information about the Twisted-Python mailing list