Promises

Mark S. Miller erights at google.com
Sat Nov 10 15:46:07 PST 2012


On Sat, Nov 10, 2012 at 11:22 AM, Kevin Smith <khs4473 at gmail.com> wrote:

>
> return AFS.stat(path)
>>    .fail(error => null) // map failure to success condition
>>    .then(stat =>
>>
>>        if (!stat)    // Path doesn't exist - create the directory
>>            return AFS.mkdir(path);
>>        else if (stat.isDirectory())    // done already
>>            return 'nothing to do';
>>        else    // no can do
>>
>>            throw new Error("Path is not a directory.");
>>
>>    ).then(val => console.log("done"));
>>
>>
> Provided that fail provides the implicit success handler `val => val`, I
> think that's correct.  Question:  is one-arg `then` + `fail` equally as
> powerful as two-arg then?  Proof?
>

Is the following a counter-example?

On Fri, Nov 9, 2012 at 8:33 AM, Mark S. Miller <erights at google.com> wrote:

> Hi David, thanks for your thoughtful post. I've always used the two-arg
> form of .then[1], but your post makes a strong case for more often using
> separate one-arg .then and .fail calls. I say only "more often" because the
> two arg form can easily make distinctions that the one-arg forms cannot
>
>     var p2 = Q(p1).then(val => { throw foo(val); },
>                         reason => { return bar(reason); });
>
> is different than either of the one-arg chainings.
>



>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121110/f7d2d6d3/attachment.html>


More information about the es-discuss mailing list