- From: Ehsan Akhgari <ehsan@mozilla.com>
- Date: Tue, 22 Oct 2013 14:33:28 -0400
- To: Jonas Sicking <jonas@sicking.cc>
- Cc: WHAT Working Group <whatwg@lists.whatwg.org>, Boris Zbarsky <bzbarsky@mit.edu>, Ian Hickson <ian@hixie.ch>, Andrew Wilson <atwilson@google.com>, Gene Lian <clian@mozilla.com>
On Tue, Oct 22, 2013 at 1:32 PM, Jonas Sicking <jonas@sicking.cc> wrote: > On Tue, Oct 22, 2013 at 9:31 AM, Ehsan Akhgari <ehsan@mozilla.com> wrote: > >> interface MessagePort { > >> ... > >> Promise pin(); > >> void unpin(optional any value); > >> }; > >> > >> Rather than firing channeldropped we reject any promise returned from > >> pin(). Once the caller receives an expected answer he/she calls unpin() > >> which resolves the promise using whatever value is passed in and so the > port > >> becomes GCable again. > >> > >> When pin() is called again after the unpin call we create a new promise > >> which again prevents the port from getting GCed. > > > > This sounds good to me, if the usage of Promise is OK in HTML these days! > >> > >> We could even expose a failAndUnpin function which rejects the promise. > >> This could be useful to enable the page to implement timeouts etc. > > > > Hmm, I'm not sure if I understand this. Can you please elaborate? > > As the API stands in the proposal above you could write code like: > > port.postMessage({ doStuff: "using-this-data" }); > port.onmessage = e => { port.unpin(e.data); }; > port.pin().then(d => doAsync(d)).then(...); > > Which is great. However if you want to implement a timeout such that > it is treated as an error if data isn't returned within 5 seconds, > that is harder to do. How to do it is left as an exercise to the > reader :) > > However it definitely could be done. So I think the above API is > certainly good enough. The failAndUnpin (or better named > unpinAndReject) method is just a convenience method. > I see. Adding such a function sounds good to me, but I don't feel strongly either way. Cheers, Ehsan
Received on Tuesday, 22 October 2013 18:34:34 UTC