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): |