Promises

Kevin Smith khs4473 at gmail.com
Fri Nov 9 13:33:41 PST 2012


>  p1.then(val => doStuff)
>>      .catch(err => console.error(err));
>>
>
> Nice: +1
>

On further thought, I'm not so sure.  Consider this code, which creates a
directory if it doesn't already exist and then logs "done".

    return AFS.stat(path).then(stat => {

        if (!stat.isDirectory())
            throw new Error("Path is not a directory.");

    }, error => {

        // Path doesn't exist - create the directory
        return AFS.mkdir(path);

    }).then(val => console.log("done"));


Breaking the error handler out into its own "fail" method seems to make
this awkward to express because the "fail" callback is assigned to the
"then" transform, instead of the original promise as intended.

I think arrow functions make the two-arg form considerably more
aesthetically pleasing.

- Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121109/1369adc9/attachment.html>


More information about the es-discuss mailing list