<div dir="ltr">Hi all,<div><br></div><div>I've been using a pattern for quite some time to collect a bunch o' deferreds in a list and then yield on them one at a time.  Here is some untested pseudocode:</div><div><br></div><div>---</div><div><font face="monospace, monospace">@defer.inlineCallbacks</font></div><div><font face="monospace, monospace">def foo( ls ):</font></div><div><font face="monospace, monospace">    defs = []</font></div><div><font face="monospace, monospace">    </font></div><div><font face="monospace, monospace">    # get all the deferreds going</font></div><div><font face="monospace, monospace">    for item in ls:</font></div><div><font face="monospace, monospace">        d = some_deferred_returning_function( item )</font></div><div><font face="monospace, monospace">        defs.append( ( item, d ) ) # associate item with deferred</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    # process results not as they come in but in the original order</font></div><div><font face="monospace, monospace">    for ( item, d ) in defs:</font></div><div><font face="monospace, monospace">        result = yield d</font></div><div><font face="monospace, monospace">        print 'The result on item', item, 'is', result</font></div><div>---</div><div><br></div><div>In this way, I can get good concurrency (by spinning up all deferreds at once) but also I can iterate on the results using a straightforward traversal of the list data structure and yield.  This is working great for me.  But on occasion I'd prefer that I can access the results not in the order that I originally got, but rather in the order of completion of the deferreds, so the faster ones come in first, and the slower ones don't hold up faster ones.  The usual case when I'd want this is when I have "slower" deferreds near the front, and "faster" deferreds near the back.  I can't help but think that there's some async data structure out there for me that can solve this.  I've used DeferredList before, and I can't see that it does what I want:  it gives you a choice between getting all results only when they are all done (default behavior), or getting the first one that's ready (<span style="color:rgb(0,0,128);font-family:monospace;font-size:medium;font-weight:bold;background-color:rgb(232,240,248)">fireOnOneCallback=True)</span>.  I want all results, but I want the processing of the results to unfold as the results come in.</div><div><br clear="all"><div>Thanks for any ideas.</div>-- <br><div class="gmail_signature">Benjamin Rutt</div>

</div></div>