| Index: third_party/mojo/src/mojo/public/python/mojo_bindings/promise.py
|
| diff --git a/third_party/mojo/src/mojo/public/python/mojo_bindings/promise.py b/third_party/mojo/src/mojo/public/python/mojo_bindings/promise.py
|
| index ebf6f85e0dcc034f3346a8a2197170012831bb2b..7ceb52c246a2820e229ada2d0c12d364cef90017 100644
|
| --- a/third_party/mojo/src/mojo/public/python/mojo_bindings/promise.py
|
| +++ b/third_party/mojo/src/mojo/public/python/mojo_bindings/promise.py
|
| @@ -149,6 +149,21 @@ class Promise(object):
|
| """Equivalent to |Then(None, onCatched)|"""
|
| return self.Then(None, onCatched)
|
|
|
| + def __getattr__(self, attribute):
|
| + """
|
| + Allows to get member of a promise. It will return a promise that will
|
| + resolve to the member of the result.
|
| + """
|
| + return self.Then(lambda v: getattr(v, attribute))
|
| +
|
| + def __call__(self, *args, **kwargs):
|
| + """
|
| + Allows to call this promise. It will return a promise that will resolved to
|
| + the result of calling the result of this promise with the given arguments.
|
| + """
|
| + return self.Then(lambda v: v(*args, **kwargs))
|
| +
|
| +
|
| def _Resolve(self, value):
|
| if self.state != Promise.STATE_PENDING:
|
| return
|
| @@ -175,6 +190,16 @@ class Promise(object):
|
| self._onRejected = None
|
|
|
|
|
| +def async(f):
|
| + def _ResolvePromises(*args, **kwargs):
|
| + keys = kwargs.keys()
|
| + values = kwargs.values()
|
| + all_args = list(args) + values
|
| + return Promise.All(*all_args).Then(
|
| + lambda r: f(*r[:len(args)], **dict(zip(keys, r[len(args):]))))
|
| + return _ResolvePromises
|
| +
|
| +
|
| def _IterateAction(iterable):
|
| def _Run(x):
|
| for f in iterable:
|
|
|