Re: Parameter to promise constructor

"Tab Atkins Jr." <[email protected]>
Newsgroups gmane.comp.web.dom.general
Message-ID <CAAWBYDB3x7JLybje7d_QB5_KbODu-6hTq11_vDfTEMo6dKtNUw__26716.142477426$1377873890$gmane$org@mail.gmail.com>
On Fri, Aug 30, 2013 at 7:33 AM, Nathan Wall <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.