That is an interesting idea. In E's when-catch construct, which is the direct ancestor of JS's .then, the when-catch construct is syntax whose expansion to Kernel-E was dependent on whether the when-catch construct statically occurs in a value consuming context. E is an expression language, but in JS terms, this is essentially the distinction between an expression-statement and other expression contexts, as in your example.
Likewise, the E message send was syntax, as in the proposed-for-ES7 infix ! syntax <http://wiki.ecmascript.org/doku.php?id=strawman:concurrency> expanded differently depending on this context difference. (In E it is "<-" which doesn't work for JS because "x <- y" already parses as "x < -y".) In E, the equivalent of "x ! m(y)" would expand to either the equivalent of "x.send('m', y)" as shown on that page, when it occurs in a value consuming context, or the equivalent of "x.sendOnly('m', y)" which differs in not creating a result promise. With your proposal, the one .send method could do both jobs by using this test. The motivation was 1) to avoid the creation of the extra local promise as you state, and 2) in the distributed case, to use the simpler distributed invocation protocol which avoids the need to create a new remote promise for the eventual remote result. < http://erights.org/elib/distrib/captp/DeliverOp.html> vs < http://erights.org/elib/distrib/captp/DeliverOnlyOp.html>. #1 is a nice optimization. #2 is a really important one. Before your suggestion, I didn't have a good idea how to reintroduce it to JS promises. Nice! On Mon, Mar 2, 2015 at 9:30 AM, John Lenz <[email protected]> wrote: > I was recently discussion Promise optimizations (specifically, that in any > "then" chain at least one Promise object is created that goes unused), this > could be solved by some metadata that indicated whether the result of the > function would be consumed: > > Promise.prototype.then = function(a, b) { > ... > if (function.called_from_void_result_context) { > return undefined; > } > /* current behavior */ > ... > }; > > > // example > > somePromise.then(); // no chaining promise created by then > > var x = somePromise.then(); // chaining promise created > x.then(); // no chaining promise created > > I'm not really sure what impact this would have on the VMs but I found it > an interesting idea. > > > > > > > > > > On Thu, Feb 26, 2015 at 2:47 PM, Allen Wirfs-Brock <[email protected]> > wrote: > >> Here is a new proposal for some additional meta properties that should be >> considered for ES7 >> https://github.com/allenwb/ESideas/blob/master/ES7MetaProps.md >> >> I've added this to the agenda for next months TC39 meeting but >> pre-meeting discussion is always welcomed right here. >> >> Allen >> >> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > > -- Cheers, --MarkM
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

