Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3600)

Unified Diff: chrome/common/extensions/docs/server2/future.py

Issue 417163004: Docserver: Update Future.Then() to be more Promise-like (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/future.py
diff --git a/chrome/common/extensions/docs/server2/future.py b/chrome/common/extensions/docs/server2/future.py
index 4b09073d4c25c0812fcbb9494dd731333f4cedf9..05f4d4224cff380a81283818994b965260060ab7 100644
--- a/chrome/common/extensions/docs/server2/future.py
+++ b/chrome/common/extensions/docs/server2/future.py
@@ -7,6 +7,10 @@ import sys
_no_value = object()
+def _DefaultErrorHandler(error):
+ raise error
+
+
def All(futures, except_pass=None):
'''Creates a Future which returns a list of results from each Future in
|futures|.
@@ -61,12 +65,15 @@ class Future(object):
self._exc_info is None):
raise ValueError('Must have either a value, error, or callback.')
- def Then(self, callback):
+ def Then(self, callback, error_handler=_DefaultErrorHandler):
Yoyo Zhou 2014/08/01 22:03:19 This should come with tests. P.S. You should make
ahernandez 2014/08/04 18:51:19 The other changes do use the new changes from futu
'''Creates and returns a future that runs |callback| on the value of this
- future.
+ future. Optional |error_handler| can be passed for custom error handling.
'''
def then():
- return callback(self.Get())
+ try:
+ return callback(self.Get())
Yoyo Zhou 2014/08/01 22:03:19 If I'm reading the Promise description correctly,
+ except Exception as e:
+ error_handler(e)
return Future(callback=then)
def Get(self):
« no previous file with comments | « chrome/common/extensions/docs/server2/file_system.py ('k') | chrome/common/extensions/docs/server2/mock_file_system.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698