Chromium Code Reviews| 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 51c284235cc7706d4f9c9df0f2740cdf18d409b0..8d6312923e0e0418bf2d34753e1854c1a02e0bd3 100644 |
| --- a/chrome/common/extensions/docs/server2/future.py |
| +++ b/chrome/common/extensions/docs/server2/future.py |
| @@ -69,13 +69,31 @@ class Future(object): |
| '''Creates and returns a future that runs |callback| on the value of this |
| future, or runs optional |error_handler| if resolving this future results in |
| an exception. |
| + |
| + If |callback| returns a Future then Then() will resolve to the same value |
|
Yoyo Zhou
2014/08/05 21:52:36
These 2 sentences are confusing next to each other
not at google - send to devlin
2014/08/05 23:00:54
This is tricky to explain. I had another go.
|
| + of that Future. Otherwise, Then() will resolve to that value. |
| + |
| + For example, |
| + |
| + def fortytwo(): |
| + return 42 |
| + def inc(x): |
| + return x + 1 |
| + def inc_future(x): |
| + return Future(value=x + 1) |
| + |
| + fortywho().Then(inc).Get() ==> 43 |
| + fortywho().Then(inc_future).Get() ==> 43 |
| ''' |
| def then(): |
| + val = None |
| try: |
| val = self.Get() |
| except Exception as e: |
| - return error_handler(e) |
| - return callback(val) |
| + val = error_handler(e) |
| + else: |
| + val = callback(val) |
| + return val.Get() if isinstance(val, Future) else val |
| return Future(callback=then) |
| def Get(self): |