W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2013

Re: Parameter to promise constructor

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Fri, 30 Aug 2013 07:43:27 -0700
Message-ID: <CAAWBYDB3x7JLybje7d_QB5_KbODu-6hTq11_vDfTEMo6dKtNUw@mail.gmail.com>
To: Nathan Wall <nathan.wall@live.com>
Cc: Domenic Denicola <domenic@domenicdenicola.com>, "es-discuss@mozilla.org" <es-discuss@mozilla.org>, "www-dom@w3c.org" <www-dom@w3c.org>, "public-script-coord@w3.org" <public-script-coord@w3.org>
On Fri, Aug 30, 2013 at 7:33 AM, Nathan Wall <nathan.wall@live.com> wrote:
> Domenica Denicola wrote:
>> Since there's no real advantage to the `PromiseResolver` approach, and there are a number of disadvantages, we were hoping to switch to the prevalent `(resolve, reject)` signature in the revised DOM promises spec.
>>
>> Let us know what you think!
>
>
> One advantage to the `PromiseResolver` is that it's easier to pass around than two separate functions.  Passing the resolver around isn't common, but at my workplace we've made use of it in a "requester" pattern.
>
>
>     function Requester() {
>         this.requests = Object.create();
>     }
>
>     Requester.prototype = {
>         respond: function(requestName, callback) {
>             this.requests[requestName] = callback;
>         },
>         request: function(requestName, ...values) {
>             return new Promise(resolver => {
>                 this.requests[requestName](resolver, ...values);
>             });
>         }
>     };

Just change this to:

    this.requests[requestName]({resolve, reject}, ...values);

Changing the argument signature has only a tiny, local effect on your code.

~TJ
Received on Friday, 30 August 2013 14:44:17 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:37:03 UTC