← Back to team overview

txamqp-user team mailing list archive

Re: How do you listen to different queues asynchronously?

 

>>>>> "Ale" == Ale  <peralta.alejandro@xxxxxxxxx> writes:

Ale> This is the sort of thing I wanted to achieve but without trapping
Ale> exceptions. I don't know how "dirty" this is (a snip, for the whole
Ale> file see paste):

Ale> def whichEverFiresFirst(def1, def2):

Hi Ale

If you want a deferred that fires with the first of n other deferreds, you
can just do this:

    from twisted.internet import defer

    d = defer.DeferredList([def1, def2], fireOnOneCallback=True)

and d will be called with a tuple containing the result of the deferred
that fired first and an index indicating which deferred it was (an index
into the list of deferreds you pass to DeferredList).

Note that this deferred (i.e., the DeferredList) cannot errback in this
case.  You should take care of errors that could occur in your deferreds.
It might help to closely read some of the code in twisted/internet/defer.py
That helped me a lot. I guess there's no real substitute.

Terry



Follow ups

References