Promises

Kevin Smith khs4473 at gmail.com
Sat Nov 10 11:22:33 PST 2012


> 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?

- Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121110/4812d4dc/attachment-0001.html>


More information about the es-discuss mailing list