On Tue, Jun 9, 2015 at 3:45 PM, Mark Miller <erig...@gmail.com> wrote:
> I don't understand your answer. p and r are plain promises. They must be > because they exist before q does. q is the first remote promise in this > scenario. How does resolving r to q leave r unsettled but give q access to > the messages buffered (and to be buffered) in r? > ``` const r = p.then(() => q); // q is a RemoteObjectPromise ``` I don't see any problem here. Perhaps you should work through the logic in `Promise#then` yourself to see that this works. Or play with the following in babel: ``` // babel doesn't implement this correctly: /* class RemotePromise extends Promise { static get [Symbol.species]() { return Promise; } } */ // -- so we need to do this: -- let RemotePromise = function(f) { let p = new Promise(f); Object.setPrototypeOf(p, RemotePromise.prototype); return p; }; Object.setPrototypeOf(RemotePromise, Promise); Object.defineProperty(RemotePromise, Symbol.species, { get: function() { return Promise; } }); RemotePromise.prototype = Object.create(Promise.prototype); RemotePromise.prototype.constructor = RemotePromise; // -- end crazy babel workaround -- let q = RemotePromise.resolve(42); // cheat, this would be the result of an RPC call let p = Promise.resolve({}); // local promise const r = p.then(() => q); // q is a RemoteObjectPromise r.then(function() { // show that this works properly! console.log(q instanceof RemotePromise, p instanceof RemotePromise, r instanceof RemotePromise); }); ``` I think where you are surprised is because (in this model) p.then() is implicitly requesting a *local* computation. Even though `() => q` in your sample code *looks* like a no-op, because q is a RemoteObjectPromise and p is not, you are explicitly requesting that the result of `q` be transferred to the local client so it can be operated on locally. If you want to continue doing remote computation, you need to use the "remote computation" methods (get/post/delete/call/etc) which keep the result on the remote server (and all of which yield a RemoteObjectPromise, not a Promise). This may differ from the E model (I don't know), but it makes good sense to me. You can't expect to do arbitrary computation inside a `then` unless the result has been transferred to the local client. --scott
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss