W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2013

Re: [whatwg] onclose events for MessagePort

From: Ehsan Akhgari <ehsan@mozilla.com>
Date: Tue, 22 Oct 2013 14:33:28 -0400
Message-ID: <CANTur_6Wd8gapRVhGV=PhdVep8d7+Z413nYQ-hze4G6b_6EJdw@mail.gmail.com>
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

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:12 UTC