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

Unified Diff: third_party/mojo/src/mojo/public/python/mojo_bindings/promise.py

Issue 975973002: Update mojo sdk to rev f68e697e389943cd9bf9652397312280e96b127a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: shake fist at msvc Created 5 years, 10 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: 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:

Powered by Google App Engine
This is Rietveld 408576698