|
|
Created:
6 years, 8 months ago by Matt Perry Modified:
6 years, 8 months ago Reviewers:
abarth-chromium CC:
chromium-reviews, Aaron Boodman, darin (slow to review), viettrungluu+watch_chromium.org, ben+mojo_chromium.org Base URL:
svn://svn.chromium.org/chrome/trunk/src Visibility:
Public. |
DescriptionMojo: Use Promises for request/response calls in the JavaScript bindings.
BUG=359812
R=abarth@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=261936
Patch Set 1 #Patch Set 2 : . #Patch Set 3 : . #Patch Set 4 : . #Patch Set 5 : rm unused code #Patch Set 6 : rebase #
Messages
Total messages: 20 (0 generated)
Here's what it looks like when we use Promises for the request/response stuff. I'm not totally convinced it's a win here, but maybe in more complex examples it will be better. I also had to jump through some hoops to get the unittest working. Promises don't execute until the stack unwinds, so I had to ensure our mock asyncWait triggered in a deferred task.
On 2014/04/04 00:42:20, Matt Perry wrote: > Here's what it looks like when we use Promises for the request/response stuff. > I'm not totally convinced it's a win here, but maybe in more complex examples it > will be better. Promises are the right JavaScript idiom to use for this situation. There isn't a big win when used in isolation like this, but when you build up a bigger system, they make it easier to keep things straight. > I also had to jump through some hoops to get the unittest working. Promises > don't execute until the stack unwinds, so I had to ensure our mock asyncWait > triggered in a deferred task. The unit testing does seem a bit ugly, but that's probably the right trade-off to make the system more programmable. LGTM
I haven't reviewed the code, but one of my goals with using ES promises here was to use it as a way to report connection errors. In the C++ bindings, we do this via the ErrorHandler interface. Instead of mapping that interface to JS, we should just dispatch an exception through the promise interface. (Sorry if you have already done so in this CL!) -Darin On Thu, Apr 3, 2014 at 10:28 PM, <abarth@chromium.org> wrote: > On 2014/04/04 00:42:20, Matt Perry wrote: > >> Here's what it looks like when we use Promises for the request/response >> stuff. >> I'm not totally convinced it's a win here, but maybe in more complex >> examples >> > it > >> will be better. >> > > Promises are the right JavaScript idiom to use for this situation. There > isn't > a big win when used in isolation like this, but when you build up a bigger > system, they make it easier to keep things straight. > > > I also had to jump through some hoops to get the unittest working. >> Promises >> don't execute until the stack unwinds, so I had to ensure our mock >> asyncWait >> triggered in a deferred task. >> > > The unit testing does seem a bit ugly, but that's probably the right > trade-off > to make the system more programmable. > > LGTM > > https://codereview.chromium.org/223043006/ > To unsubscribe from this group and stop receiving emails from it, send an email to chromium-reviews+unsubscribe@chromium.org.
The CQ bit was checked by mpcomplete@chromium.org
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/mpcomplete@chromium.org/223043006/80001
No error handling with this CL, but I can look at that next. On 2014/04/04 05:34:18, darin wrote: > I haven't reviewed the code, but one of my goals with using ES promises > here was to use it as a way to report connection errors. In the C++ > bindings, we do this via the ErrorHandler interface. Instead of mapping > that interface to JS, we should just dispatch an exception through the > promise interface. (Sorry if you have already done so in this CL!) > > -Darin > > > On Thu, Apr 3, 2014 at 10:28 PM, <mailto:abarth@chromium.org> wrote: > > > On 2014/04/04 00:42:20, Matt Perry wrote: > > > >> Here's what it looks like when we use Promises for the request/response > >> stuff. > >> I'm not totally convinced it's a win here, but maybe in more complex > >> examples > >> > > it > > > >> will be better. > >> > > > > Promises are the right JavaScript idiom to use for this situation. There > > isn't > > a big win when used in isolation like this, but when you build up a bigger > > system, they make it easier to keep things straight. > > > > > > I also had to jump through some hoops to get the unittest working. > >> Promises > >> don't execute until the stack unwinds, so I had to ensure our mock > >> asyncWait > >> triggered in a deferred task. > >> > > > > The unit testing does seem a bit ugly, but that's probably the right > > trade-off > > to make the system more programmable. > > > > LGTM > > > > https://codereview.chromium.org/223043006/ > > > > To unsubscribe from this group and stop receiving emails from it, send an email > to mailto:chromium-reviews+unsubscribe@chromium.org.
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/mpcomplete@chromium.org/223043006/80001
The CQ bit was unchecked by commit-bot@chromium.org
Failed to apply patch for mojo/public/bindings/generators/js_templates/interface_definition.tmpl: While running patch -p1 --forward --force --no-backup-if-mismatch; A mojo/public/bindings Created missing directory mojo/public/bindings. A mojo/public/bindings/generators Created missing directory mojo/public/bindings/generators. A mojo/public/bindings/generators/js_templates Created missing directory mojo/public/bindings/generators/js_templates. can't find file to patch at input line 6 Perhaps you used the wrong -p or --strip option? The text leading up to this was: -------------------------- |Index: mojo/public/bindings/generators/js_templates/interface_definition.tmpl |diff --git a/mojo/public/bindings/generators/js_templates/interface_definition.tmpl b/mojo/public/bindings/generators/js_templates/interface_definition.tmpl |index fc77059e76ce136790ada9529ba66248916b9a1e..3a42ae5618afe81fa5144f6486315edca057a71d 100644 |--- a/mojo/public/bindings/generators/js_templates/interface_definition.tmpl |+++ b/mojo/public/bindings/generators/js_templates/interface_definition.tmpl -------------------------- No file to patch. Skipping patch. 3 out of 3 hunks ignored Patch: mojo/public/bindings/generators/js_templates/interface_definition.tmpl Index: mojo/public/bindings/generators/js_templates/interface_definition.tmpl diff --git a/mojo/public/bindings/generators/js_templates/interface_definition.tmpl b/mojo/public/bindings/generators/js_templates/interface_definition.tmpl index fc77059e76ce136790ada9529ba66248916b9a1e..3a42ae5618afe81fa5144f6486315edca057a71d 100644 --- a/mojo/public/bindings/generators/js_templates/interface_definition.tmpl +++ b/mojo/public/bindings/generators/js_templates/interface_definition.tmpl @@ -11,9 +11,6 @@ {%- for parameter in method.parameters -%} {{parameter.name}}{% if not loop.last %}, {% endif %} {%- endfor -%} -{%- if method.response_parameters != None -%} -, closure -{%- endif -%} ) { var params = new {{interface.name}}_{{method.name}}_Params(); {%- for parameter in method.parameters %} @@ -28,21 +25,20 @@ var message = builder.finish(); this.receiver_.accept(message); {%- else %} - var builder = new codec.MessageWithRequestIDBuilder( - k{{interface.name}}_{{method.name}}_Name, - codec.align({{interface.name}}_{{method.name}}_Params.encodedSize), - codec.kMessageExpectsResponse, 0); - builder.encodeStruct({{interface.name}}_{{method.name}}_Params, params); - var message = builder.finish(); - this.receiver_.acceptWithResponder(message, { accept: function(message) { - var reader = new codec.MessageReader(message); - var responseParams = - reader.decodeStruct({{interface.name}}_{{method.name}}_ResponseParams); - closure( -{%- for parameter in method.response_parameters -%} -responseParams.{{parameter.name}}{% if not loop.last %}, {% endif %} -{%- endfor -%}); - }}); + return new Promise(function(resolve, reject) { + var builder = new codec.MessageWithRequestIDBuilder( + k{{interface.name}}_{{method.name}}_Name, + codec.align({{interface.name}}_{{method.name}}_Params.encodedSize), + codec.kMessageExpectsResponse, 0); + builder.encodeStruct({{interface.name}}_{{method.name}}_Params, params); + var message = builder.finish(); + this.receiver_.acceptWithResponder(message, { accept: function(message) { + var reader = new codec.MessageReader(message); + var responseParams = + reader.decodeStruct({{interface.name}}_{{method.name}}_ResponseParams); + resolve(responseParams); + }}); + }.bind(this)); {%- endif %} }; {%- endfor %} @@ -79,15 +75,12 @@ params.{{parameter.name}}{% if not loop.last %}, {% endif %} var params = reader.decodeStruct({{interface.name}}_{{method.name}}_Params); this.{{method.name|stylize_method}}( {%- for parameter in method.parameters -%} -params.{{parameter.name}}, -{%- endfor %} function ( -{%- for parameter in method.response_parameters -%} -{{parameter.name}}{% if not loop.last %}, {% endif -%} -{%- endfor -%}) { +params.{{parameter.name}}{% if not loop.last %}, {% endif -%} +{%- endfor %}).then(function(response) { var responseParams = new {{interface.name}}_{{method.name}}_ResponseParams(); {%- for parameter in method.response_parameters %} - responseParams.{{parameter.name}} = {{parameter.name}}; + responseParams.{{parameter.name}} = response.{{parameter.name}}; {%- endfor %} var builder = new codec.MessageWithRequestIDBuilder( k{{interface.name}}_{{method.name}}_Name,
The CQ bit was checked by mpcomplete@chromium.org
The CQ bit was unchecked by mpcomplete@chromium.org
The CQ bit was checked by mpcomplete@chromium.org
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/mpcomplete@chromium.org/223043006/100001
The CQ bit was unchecked by commit-bot@chromium.org
Try jobs failed on following builders: tryserver.chromium on linux_chromium_clang_dbg
The CQ bit was checked by mpcomplete@chromium.org
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/mpcomplete@chromium.org/223043006/100001
The CQ bit was unchecked by commit-bot@chromium.org
Try jobs failed on following builders: tryserver.chromium on linux_chromium_clang_dbg
Message was sent while issue was closed.
Committed patchset #6 manually as r261936 (presubmit successful). |