From 5d5e89d96d7a78d28399d955e28eabee36ed28d6 Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Sun, 4 Jan 2009 10:52:02 -0700 Subject: [PATCH] util: add gatherResults which is a deferred-list-like thing that doesn't wrap failures in a FirstError --- src/allmydata/util/deferredutil.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/allmydata/util/deferredutil.py b/src/allmydata/util/deferredutil.py index ca62e5ae..8f37ce0d 100644 --- a/src/allmydata/util/deferredutil.py +++ b/src/allmydata/util/deferredutil.py @@ -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 + -- 2.45.2