summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/server2/future.py
diff options
context:
space:
mode:
authorkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-13 20:54:49 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-13 20:54:49 +0000
commitc759544f511a0286b28262826d1e623cbd61b020 (patch)
treeac3d0bb935e21ce1bc95078da8f1be78ba7f933a /chrome/common/extensions/docs/server2/future.py
parent30f1d94eb1d6de64b840930035053dc412a90d3e (diff)
downloadchromium_src-c759544f511a0286b28262826d1e623cbd61b020.zip
chromium_src-c759544f511a0286b28262826d1e623cbd61b020.tar.gz
chromium_src-c759544f511a0286b28262826d1e623cbd61b020.tar.bz2
Docserver: Implement ContentProvider.GetVersion.
BUG=402903 R=yoz@chromium.org NOTRY=true Review URL: https://codereview.chromium.org/462103003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289373 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/server2/future.py')
-rw-r--r--chrome/common/extensions/docs/server2/future.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/chrome/common/extensions/docs/server2/future.py b/chrome/common/extensions/docs/server2/future.py
index 2a13611..289761c 100644
--- a/chrome/common/extensions/docs/server2/future.py
+++ b/chrome/common/extensions/docs/server2/future.py
@@ -2,7 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import logging
import sys
+import traceback
_no_value = object()
@@ -11,12 +13,15 @@ def _DefaultErrorHandler(error):
raise error
-def All(futures, except_pass=None):
+def All(futures, except_pass=None, except_pass_log=False):
'''Creates a Future which returns a list of results from each Future in
|futures|.
If any Future raises an error other than those in |except_pass| the returned
Future will raise as well.
+
+ If any Future raises an error in |except_pass| then None will be inserted as
+ its result. If |except_pass_log| is True then the exception will be logged.
'''
def resolve():
resolved = []
@@ -25,17 +30,21 @@ def All(futures, except_pass=None):
resolved.append(f.Get())
# "except None" will simply not catch any errors.
except except_pass:
+ if except_pass_log:
+ logging.error(traceback.format_exc())
+ resolved.append(None)
pass
return resolved
return Future(callback=resolve)
-def Race(futures, except_pass=None):
+def Race(futures, except_pass=None, default=_no_value):
'''Returns a Future which resolves to the first Future in |futures| that
either succeeds or throws an error apart from those in |except_pass|.
- If all Futures throw errors in |except_pass| then the returned Future
- will re-throw one of those errors, for a nice stack trace.
+ If all Futures throw errors in |except_pass| then |default| is returned,
+ if specified. If |default| is not specified then one of the passed errors
+ will be re-thrown, for a nice stack trace.
'''
def resolve():
first_future = None
@@ -47,8 +56,10 @@ def Race(futures, except_pass=None):
# "except None" will simply not catch any errors.
except except_pass:
pass
- # Everything failed, propagate the first error even though it was
- # caught by |except_pass|.
+ if default is not _no_value:
+ return default
+ # Everything failed and there is no default value, propagate the first
+ # error even though it was caught by |except_pass|.
return first_future.Get()
return Future(callback=resolve)