[Twisted-Python] Making DeferredList look like Deferred

I have a need to return a DeferredList or a Deferred from a function, but I don't want the caller to be aware of this distinction -- the caller should just assume that they got a regular Deferred. The way I'm currently accomplishing this is to 1) ensure that each Deferred in the List has its own callback/errback pair hooked up, and 2) add a callback to the Deferred list from within the called function which either returns the [possibly sanitized] result if all the Deferreds called their callbacks, or that raises a failure.DefaultException if any of the Deferreds called their errbacks. This seems to give me the desired result in all cases. Is this the right way to go about this? Is there a cleaner way? (The reason I can't just return the DeferredList, as I understand, is that its callback is *always* invoked, even if we leave each of the Deferred's errbacks unhooked and let them trickle up into DeferredList's addErrback callable. In the case of a caller who expects the returned deferred to be a regular deferred, it would not be expected to have *both* its callback and errback invoked). thanks, Lenny __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

On Fri, 3 Feb 2006 12:18:56 -0800 (PST), Lenny G Arbage <alengarbage@yahoo.com> wrote:
DeferredList has *either* callback *or* errback called on it, just like any Deferred. If you just give it a list of Deferreds, it will always have its callback method invoked and never have its errback method invoked, regardless of whether any of the Deferreds it was constructed with fail. However, if you pass a true value for fireOnOneErrback when constructing your DeferredList, any Deferred which errbacks will cause the DeferredList to errback; in this case it will never callback. Does that help? Jean-Paul

On Fri, 3 Feb 2006 12:18:56 -0800 (PST), Lenny G Arbage <alengarbage@yahoo.com> wrote:
DeferredList has *either* callback *or* errback called on it, just like any Deferred. If you just give it a list of Deferreds, it will always have its callback method invoked and never have its errback method invoked, regardless of whether any of the Deferreds it was constructed with fail. However, if you pass a true value for fireOnOneErrback when constructing your DeferredList, any Deferred which errbacks will cause the DeferredList to errback; in this case it will never callback. Does that help? Jean-Paul
participants (2)
-
Jean-Paul Calderone
-
Lenny G Arbage