]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
util: add gatherResults which is a deferred-list-like thing that doesn't wrap failure...
authorZooko O'Whielacronx <zooko@zooko.com>
Sun, 4 Jan 2009 17:52:02 +0000 (10:52 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Sun, 4 Jan 2009 17:52:02 +0000 (10:52 -0700)
src/allmydata/util/deferredutil.py

index ca62e5aec753ed422aa54433c0815e910dc921d8..8f37ce0d53e050e8ab03c1e558aa7ee98e772918 100644 (file)
@@ -15,3 +15,22 @@ def DeferredListShouldSucceed(dl):
     d.addCallback(_check_deferred_list)
     return d
 
+def _parseDListResult(l):
+    return [x[1] for x in l]
+
+def _unwrapFirstError(f):
+    f.trap(defer.FirstError)
+    raise f.value.subFailure
+
+def gatherResults(deferredList):
+    """Returns list with result of given Deferreds.
+
+    This builds on C{DeferredList} but is useful since you don't
+    need to parse the result for success/failure.
+
+    @type deferredList:  C{list} of L{Deferred}s
+    """
+    d = defer.DeferredList(deferredList, fireOnOneErrback=True, consumeErrors=True)
+    d.addCallbacks(_parseDListResult, _unwrapFirstError)
+    return d
+